Skip to content

Commit

Permalink
feat: make stacktrace of the logger configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
anvari1313 committed Sep 10, 2024
1 parent c16fed2 commit 06da692
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

type Config struct {
Level string `json:"level,omitempty" koanf:"level"`
Level string `json:"level,omitempty" koanf:"level"`

Check failure on line 12 in internal/logger/logger.go

View workflow job for this annotation

GitHub Actions / lint

tag is not aligned, should be: json:"level,omitempty" koanf:"level" (tagalign)
Stacktrace bool `json:"stacktrace,omitempty" koanf:"stacktrace"`
}

// New creates a zap logger for console.
Expand All @@ -28,7 +29,12 @@ func New(cfg Config) *zap.Logger {
}

core := zapcore.NewTee(cores...)
logger := zap.New(core, zap.AddCaller(), zap.AddStacktrace(zap.ErrorLevel))
var zapOpts = make([]zap.Option, 0, 2)
zapOpts = append(zapOpts, zap.AddCaller())
if cfg.Stacktrace {

Check failure on line 34 in internal/logger/logger.go

View workflow job for this annotation

GitHub Actions / lint

only one cuddle assignment allowed before if statement (wsl)
zapOpts = append(zapOpts, zap.AddStacktrace(zap.ErrorLevel))
}
logger := zap.New(core, zapOpts...)

Check failure on line 37 in internal/logger/logger.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)

return logger
}

0 comments on commit 06da692

Please sign in to comment.