-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved logging, can change level via LOG_LEVEL env var
- Loading branch information
1 parent
b9dabf5
commit 1832551
Showing
3 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package logging | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
func DefaultConfig() zap.Config { | ||
logConf := zap.NewProductionConfig() | ||
logConf.Sampling = nil | ||
logConf.EncoderConfig.TimeKey = "time" | ||
logConf.EncoderConfig.LevelKey = "severity" | ||
logConf.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder | ||
logConf.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder | ||
|
||
return logConf | ||
} | ||
|
||
func ParseLevel(l string) (zapcore.Level, error) { | ||
l = strings.ToLower(strings.TrimSpace(l)) | ||
switch l { | ||
case "debug": | ||
return zapcore.DebugLevel, nil | ||
case "info": | ||
return zapcore.InfoLevel, nil | ||
case "warn": | ||
return zapcore.WarnLevel, nil | ||
case "error": | ||
return zapcore.ErrorLevel, nil | ||
case "dpanic": | ||
return zapcore.DPanicLevel, nil | ||
case "panic": | ||
return zapcore.PanicLevel, nil | ||
case "fatal": | ||
return zapcore.FatalLevel, nil | ||
default: | ||
level, err := strconv.ParseInt(l, 10, 8) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return zapcore.Level(level), nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters