37 lines
1006 B
Go
37 lines
1006 B
Go
package dependencies
|
|
|
|
import (
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
func setupLogger() *zap.Logger {
|
|
highPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
|
|
return lvl >= zapcore.ErrorLevel
|
|
})
|
|
lowPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
|
|
return lvl < zapcore.ErrorLevel
|
|
})
|
|
fileDebugging := zapcore.AddSync(ioutil.Discard)
|
|
fileErrors := zapcore.AddSync(ioutil.Discard)
|
|
|
|
consoleDebugging := zapcore.Lock(os.Stdout)
|
|
consoleErrors := zapcore.Lock(os.Stderr)
|
|
|
|
fileEncoder := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
|
|
_ = zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig())
|
|
|
|
core := zapcore.NewTee(
|
|
zapcore.NewCore(fileEncoder, fileErrors, highPriority),
|
|
zapcore.NewCore(fileEncoder, consoleErrors, highPriority),
|
|
zapcore.NewCore(fileEncoder, fileDebugging, lowPriority),
|
|
zapcore.NewCore(fileEncoder, consoleDebugging, lowPriority),
|
|
)
|
|
|
|
logger := zap.New(core)
|
|
defer logger.Sync()
|
|
return logger
|
|
}
|