2022-09-10 00:09:09 +02:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
)
|
|
|
|
|
|
|
|
func New() (*zap.Logger, error) {
|
|
|
|
highPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
|
|
|
|
return lvl >= zapcore.ErrorLevel
|
|
|
|
})
|
|
|
|
lowPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
|
2022-09-21 22:55:52 +02:00
|
|
|
return lvl < zapcore.ErrorLevel // && lvl > zapcore.DebugLevel
|
2022-09-10 00:09:09 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
config := zap.NewDevelopmentEncoderConfig()
|
|
|
|
config.EncodeTime = nil
|
|
|
|
config.EncodeLevel = zapcore.CapitalColorLevelEncoder
|
|
|
|
consoleEncoder := zapcore.NewConsoleEncoder(config)
|
|
|
|
consoleDebugging := zapcore.Lock(os.Stdout)
|
|
|
|
consoleErrors := zapcore.Lock(os.Stderr)
|
|
|
|
|
|
|
|
core := zapcore.NewTee(
|
|
|
|
zapcore.NewCore(consoleEncoder, consoleErrors, highPriority),
|
|
|
|
zapcore.NewCore(consoleEncoder, consoleDebugging, lowPriority),
|
|
|
|
)
|
|
|
|
|
|
|
|
logger := zap.New(core)
|
2022-09-21 22:55:52 +02:00
|
|
|
|
2022-09-10 00:09:09 +02:00
|
|
|
return logger, nil
|
|
|
|
}
|