config rework to handle distributed setup, fixed redis bugs

This commit is contained in:
David Zhao
2021-01-17 17:06:50 -08:00
parent 30e99e8c6b
commit 458241d1f1
21 changed files with 382 additions and 104 deletions
+18 -10
View File
@@ -2,30 +2,38 @@ package logger
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var (
logger *zap.SugaredLogger
zapOptions = []zap.Option{
zap.AddCallerSkip(1),
}
logger *zap.SugaredLogger
)
func getLogger() *zap.SugaredLogger {
if logger == nil {
InitDevelopment()
InitDevelopment("")
}
return logger
}
func InitProduction() {
l, _ := zap.NewProduction(zapOptions...)
func initLogger(config zap.Config, level string) {
if level != "" {
lvl := zapcore.Level(0)
if err := lvl.UnmarshalText([]byte(level)); err == nil {
config.Level = zap.NewAtomicLevelAt(lvl)
}
}
l, _ := config.Build(zap.AddCallerSkip(1))
logger = l.Sugar()
}
func InitDevelopment() {
l, _ := zap.NewDevelopment(zapOptions...)
logger = l.Sugar()
func InitProduction(logLevel string) {
initLogger(zap.NewProductionConfig(), logLevel)
}
func InitDevelopment(logLevel string) {
initLogger(zap.NewDevelopmentConfig(), logLevel)
}
func Debugw(msg string, keysAndValues ...interface{}) {