@@ -14,7 +14,7 @@ var _logLevel = ""
1414func Init (level string ) {
1515 _logLevel = strings .ToLower (level )
1616
17- logLevel := getLogLevel (_logLevel )
17+ logLevel := ParseLevel (_logLevel )
1818
1919 cfg := zap.Config {
2020 Level : zap .NewAtomicLevelAt (logLevel ),
@@ -29,7 +29,7 @@ func Init(level string) {
2929 MessageKey : "msg" ,
3030 StacktraceKey : "stacktrace" ,
3131 LineEnding : zapcore .DefaultLineEnding ,
32- EncodeLevel : zapcore . CapitalColorLevelEncoder ,
32+ EncodeLevel : CustomEncodeLevel ,
3333 EncodeTime : zapcore .TimeEncoderOfLayout ("02.01 15:04" ),
3434 EncodeDuration : zapcore .StringDurationEncoder ,
3535 EncodeCaller : zapcore .ShortCallerEncoder ,
@@ -43,31 +43,12 @@ func Init(level string) {
4343 _log , err = cfg .Build (zap .AddCaller (), zap .AddCallerSkip (1 ))
4444
4545 if err != nil {
46- fmt .Println ("Encountered Error during Log.Init(): err.Error()" )
47- }
48- }
49-
50- func getLogLevel (level string ) zapcore.Level {
51- switch level {
52- case "info" :
53- return zapcore .InfoLevel
54- case "debug" :
55- return zapcore .DebugLevel
56- case "dev" :
57- return zapcore .DebugLevel
58- case "warn" :
59- return zapcore .WarnLevel
60- case "error" :
61- return zapcore .ErrorLevel
62- case "fatal" :
63- return zapcore .FatalLevel
64- default :
65- return zapcore .InfoLevel
46+ fmt .Println ("Encountered Error during Log.Init(): " , err .Error ())
6647 }
6748}
6849
6950func Level () string {
70- return _log .Level (). String ( )
51+ return LevelString ( _log .Level ())
7152}
7253
7354func Info (msg ... string ) {
@@ -79,8 +60,10 @@ func Debug(msg ...string) {
7960}
8061
8162func Dev (msg ... string ) {
82- if _logLevel == "dev" {
83- _log .Debug (strings .Join (msg , "" ))
63+ ok := _log .Check (DeveloperLevel , strings .Join (msg , "" ))
64+
65+ if ok != nil {
66+ ok .Write ()
8467 }
8568}
8669
0 commit comments