Last active
August 22, 2023 08:19
-
-
Save winston-wen/66718f95ef3c82313f5bbf797f286edc to your computer and use it in GitHub Desktop.
Revisions
-
winston-wen revised this gist
Aug 22, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ func InitLogger() { core := zapcore.NewCore( zapcore.NewJSONEncoder(conf_enc), w2, log_level, ) log := zap.New(core) zap.ReplaceGlobals(log) -
winston-wen revised this gist
Aug 22, 2023 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,8 @@ import ( lbj "gopkg.in/natefinch/lumberjack.v2" ) var log_level zap.AtomicLevel = zap.NewAtomicLevelAt(zap.InfoLevel) func InitLogger() { w := zapcore.AddSync(&lbj.Logger{ Filename: "logs/app_name.log", @@ -33,6 +35,7 @@ func InitLogger() { func main() { InitLogger() defer zap.S().Sync() log_level.SetLevel(zap.DebugLevel) for i := 0; i < 114514; i++ { for j := 0; j < 1919; j++ { zap.S().Debugw("test", "i", i, "j", j) -
winston-wen revised this gist
Aug 22, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,8 +10,8 @@ import ( func InitLogger() { w := zapcore.AddSync(&lbj.Logger{ Filename: "logs/app_name.log", MaxSize: 4, // MB per file // 15 old files and 1 new file. The new file has no suffix. MaxBackups: 15, -
winston-wen created this gist
Aug 22, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ package main import ( "os" "go.uber.org/zap" "go.uber.org/zap/zapcore" lbj "gopkg.in/natefinch/lumberjack.v2" ) func InitLogger() { w := zapcore.AddSync(&lbj.Logger{ Filename: "logs/nesha_server.log", MaxSize: 4, // MB // 15 old files and 1 new file. The new file has no suffix. MaxBackups: 15, }) w2 := zapcore.NewMultiWriteSyncer(w, zapcore.AddSync(os.Stdout)) conf_enc := zap.NewProductionEncoderConfig() conf_enc.LevelKey = "lv" conf_enc.CallerKey = "pos" conf_enc.EncodeTime = zapcore.ISO8601TimeEncoder core := zapcore.NewCore( zapcore.NewJSONEncoder(conf_enc), w2, zap.DebugLevel, ) log := zap.New(core) zap.ReplaceGlobals(log) } func main() { InitLogger() defer zap.S().Sync() for i := 0; i < 114514; i++ { for j := 0; j < 1919; j++ { zap.S().Debugw("test", "i", i, "j", j) } } }