github.com/yandex/pandora@v0.5.32/lib/answlog/logger.go (about) 1 package answlog 2 3 import ( 4 "os" 5 6 "go.uber.org/zap" 7 "go.uber.org/zap/zapcore" 8 ) 9 10 func Init(path string, enabled bool) *zap.Logger { 11 if !enabled { 12 return zap.NewNop() 13 } 14 writerSyncer := getAnswWriter(path) 15 encoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()) 16 core := zapcore.NewCore(encoder, writerSyncer, zapcore.DebugLevel) 17 18 Log := zap.New(core) 19 defer Log.Sync() 20 return Log 21 } 22 23 func getAnswWriter(path string) zapcore.WriteSyncer { 24 if path == "" { 25 path = "./answ.log" 26 } 27 file, _ := os.Create(path) 28 return zapcore.AddSync(file) 29 }