modify readme, add example
This commit is contained in:
parent
58a846e055
commit
aa856039ae
38
README.md
38
README.md
|
@ -12,24 +12,32 @@ package main
|
|||
import(
|
||||
"git.hpds.cc/Component/logging"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
"go.uber.org/zap/zap"
|
||||
)
|
||||
|
||||
func main(){
|
||||
opt := Options{
|
||||
Path : "./log/",
|
||||
Prefix : "",
|
||||
ErrorFileSuffix: "",
|
||||
WarnFileSuffix : "",
|
||||
InfoFileSuffix : "",
|
||||
DebugFileSuffix: "",
|
||||
Level : zapcore.DebugLevel,
|
||||
MaxSize : 100,
|
||||
MaxBackups : 1000,
|
||||
MaxAge : 30,
|
||||
Development : true,
|
||||
}
|
||||
logger := logging.NewLogger(opt)
|
||||
logger := LoadLoggerConfig()
|
||||
logger.Info("this is a test log")
|
||||
//也可以这样直接使用
|
||||
|
||||
logging.L().Info("this is a test log")
|
||||
}
|
||||
|
||||
// LoadLoggerConfig 加载日志配置
|
||||
func LoadLoggerConfig() *logging.Logger {
|
||||
return logging.NewLogger(
|
||||
logging.SetPath("./log/"),
|
||||
logging.SetPrefix(""),
|
||||
logging.SetDevelopment(true),
|
||||
logging.SetDebugFileSuffix(""),
|
||||
logging.SetWarnFileSuffix(""),
|
||||
logging.SetErrorFileSuffix(""),
|
||||
logging.SetInfoFileSuffix(""),
|
||||
logging.SetMaxAge(30),
|
||||
logging.SetMaxBackups(100),
|
||||
logging.SetMaxSize(100),
|
||||
logging.SetLevel(logging.LogLevel["debug"]),
|
||||
)
|
||||
}
|
||||
|
||||
```
|
10
logger.go
10
logger.go
|
@ -35,6 +35,7 @@ var (
|
|||
errWS, warnWS, infoWS, debugWS zapcore.WriteSyncer // IO输出
|
||||
debugConsoleWS = zapcore.Lock(os.Stdout) // 控制台标准输出
|
||||
errorConsoleWS = zapcore.Lock(os.Stderr)
|
||||
LogLevel = make(map[string]zapcore.Level)
|
||||
)
|
||||
|
||||
type Logger struct {
|
||||
|
@ -99,6 +100,15 @@ func (logger *Logger) init() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
LogLevel["debug"] = zap.DebugLevel
|
||||
LogLevel["info"] = zap.InfoLevel
|
||||
LogLevel["warn"] = zap.WarnLevel
|
||||
LogLevel["error"] = zap.ErrorLevel
|
||||
LogLevel["dpanic"] = zap.DPanicLevel
|
||||
LogLevel["panic"] = zap.PanicLevel
|
||||
LogLevel["fatal"] = zap.FatalLevel
|
||||
|
||||
defer logger.Logger.Sync()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue