Skip to content

Commit

Permalink
feat(logger): add debug parameter for logger init
Browse files Browse the repository at this point in the history
  • Loading branch information
EverythingSuckz committed Jan 2, 2025
1 parent 40cad00 commit a8dceaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/fsb/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var runCmd = &cobra.Command{
var startTime time.Time = time.Now()

func runApp(cmd *cobra.Command, args []string) {
utils.InitLogger()
utils.InitLogger(config.ValueOf.Dev)
log := utils.Logger
mainLogger := log.Named("Main")
mainLogger.Info("Starting server")
Expand Down
11 changes: 9 additions & 2 deletions internal/utils/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var Logger *zap.Logger

func InitLogger() {
func InitLogger(debugMode bool) {
customTimeEncoder := func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
enc.AppendString(t.Format("02/01/2006 03:04 PM"))
}
Expand All @@ -32,8 +32,15 @@ func InitLogger() {
Compress: true,
})

var consoleLevel zapcore.Level
if debugMode {
consoleLevel = zapcore.DebugLevel
} else {
consoleLevel = zapcore.InfoLevel
}

core := zapcore.NewTee(
zapcore.NewCore(consoleEncoder, zapcore.AddSync(os.Stdout), zapcore.InfoLevel),
zapcore.NewCore(consoleEncoder, zapcore.AddSync(os.Stdout), consoleLevel),
zapcore.NewCore(fileEncoder, fileWriter, zapcore.DebugLevel),
)

Expand Down

0 comments on commit a8dceaf

Please sign in to comment.