Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hardcoded '2' in Output with const CallDepth #137

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions log/stdlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const (
LevelDebug
)

// CallDepth is the call depth value for the log.Logger's Output method
// This defaults to 2 and is only here for better readablity of the code
const CallDepth = 2

// New returns a new Stdlog type that satisfies the Logger interface
func New(o io.Writer, l Level) *Stdlog {
lf := log.Lmsgprefix | log.LstdFlags
Expand All @@ -48,27 +52,27 @@ func New(o io.Writer, l Level) *Stdlog {
// Debugf performs a Printf() on the debug logger
func (l *Stdlog) Debugf(f string, v ...interface{}) {
if l.l >= LevelDebug {
_ = l.debug.Output(2, fmt.Sprintf(f, v...))
_ = l.debug.Output(CallDepth, fmt.Sprintf(f, v...))
}
}

// Infof performs a Printf() on the info logger
func (l *Stdlog) Infof(f string, v ...interface{}) {
if l.l >= LevelInfo {
_ = l.info.Output(2, fmt.Sprintf(f, v...))
_ = l.info.Output(CallDepth, fmt.Sprintf(f, v...))
}
}

// Warnf performs a Printf() on the warn logger
func (l *Stdlog) Warnf(f string, v ...interface{}) {
if l.l >= LevelWarn {
_ = l.warn.Output(2, fmt.Sprintf(f, v...))
_ = l.warn.Output(CallDepth, fmt.Sprintf(f, v...))
}
}

// Errorf performs a Printf() on the error logger
func (l *Stdlog) Errorf(f string, v ...interface{}) {
if l.l >= LevelError {
_ = l.err.Output(2, fmt.Sprintf(f, v...))
_ = l.err.Output(CallDepth, fmt.Sprintf(f, v...))
}
}