part of utils/zaplog.go:
// NewZapLogger initializes then returns a zap.Logger.
func NewZapLogger(path string) *zap.Logger {
dir := filepath.Dir(path)
if exist, _ := exists(dir); !exist {
if err := os.MkdirAll(dir, 0775); err != nil {
panic(fmt.Sprintf("Fail to create log directory: %v", err))
}
}
_, close, err := zap.Open(path)
if err != nil {
close()
panic(fmt.Sprintf("Fail to create/open log file: %v", err))
}
encoderConfig := zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
StacktraceKey: "stacktrace",
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.ISO8601TimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
EncodeCaller: zapcore.FullCallerE