Skip to content

Commit

Permalink
fix(logger): call depth for logging events (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn committed Jan 16, 2024
1 parent dc17340 commit 1bbdc90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ linters:

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- errcheck
- unparam
- prealloc
- funlen
- path: logger/simple_logger.go
linters:
- errcheck
21 changes: 11 additions & 10 deletions logger/simple_logger.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logger

import (
"fmt"
"log"
)

Expand Down Expand Up @@ -34,7 +35,7 @@ func NewSimpleLogger(logger *log.Logger, level Level) *SimpleLogger {
func (l *SimpleLogger) Trace(msg any) {
if l.Enabled(LevelTrace) {
l.logger.SetPrefix(TracePrefix)
l.logger.Println(msg)
l.logger.Output(3, fmt.Sprint(msg))
}
}

Expand All @@ -43,7 +44,7 @@ func (l *SimpleLogger) Trace(msg any) {
func (l *SimpleLogger) Tracef(format string, args ...any) {
if l.Enabled(LevelTrace) {
l.logger.SetPrefix(TracePrefix)
l.logger.Printf(format, args...)
l.logger.Output(3, fmt.Sprintf(format, args...))
}
}

Expand All @@ -52,7 +53,7 @@ func (l *SimpleLogger) Tracef(format string, args ...any) {
func (l *SimpleLogger) Debug(msg any) {
if l.Enabled(LevelDebug) {
l.logger.SetPrefix(DebugPrefix)
l.logger.Println(msg)
l.logger.Output(3, fmt.Sprint(msg))
}
}

Expand All @@ -61,7 +62,7 @@ func (l *SimpleLogger) Debug(msg any) {
func (l *SimpleLogger) Debugf(format string, args ...any) {
if l.Enabled(LevelDebug) {
l.logger.SetPrefix(DebugPrefix)
l.logger.Printf(format, args...)
l.logger.Output(3, fmt.Sprintf(format, args...))
}
}

Expand All @@ -70,7 +71,7 @@ func (l *SimpleLogger) Debugf(format string, args ...any) {
func (l *SimpleLogger) Info(msg any) {
if l.Enabled(LevelInfo) {
l.logger.SetPrefix(InfoPrefix)
l.logger.Println(msg)
l.logger.Output(3, fmt.Sprint(msg))
}
}

Expand All @@ -79,7 +80,7 @@ func (l *SimpleLogger) Info(msg any) {
func (l *SimpleLogger) Infof(format string, args ...any) {
if l.Enabled(LevelInfo) {
l.logger.SetPrefix(InfoPrefix)
l.logger.Printf(format, args...)
l.logger.Output(3, fmt.Sprintf(format, args...))
}
}

Expand All @@ -88,7 +89,7 @@ func (l *SimpleLogger) Infof(format string, args ...any) {
func (l *SimpleLogger) Warn(msg any) {
if l.Enabled(LevelWarn) {
l.logger.SetPrefix(WarnPrefix)
l.logger.Println(msg)
l.logger.Output(3, fmt.Sprint(msg))
}
}

Expand All @@ -97,7 +98,7 @@ func (l *SimpleLogger) Warn(msg any) {
func (l *SimpleLogger) Warnf(format string, args ...any) {
if l.Enabled(LevelWarn) {
l.logger.SetPrefix(WarnPrefix)
l.logger.Printf(format, args...)
l.logger.Output(3, fmt.Sprintf(format, args...))
}
}

Expand All @@ -106,7 +107,7 @@ func (l *SimpleLogger) Warnf(format string, args ...any) {
func (l *SimpleLogger) Error(msg any) {
if l.Enabled(LevelError) {
l.logger.SetPrefix(ErrorPrefix)
l.logger.Println(msg)
l.logger.Output(3, fmt.Sprint(msg))
}
}

Expand All @@ -115,7 +116,7 @@ func (l *SimpleLogger) Error(msg any) {
func (l *SimpleLogger) Errorf(format string, args ...any) {
if l.Enabled(LevelError) {
l.logger.SetPrefix(ErrorPrefix)
l.logger.Printf(format, args...)
l.logger.Output(3, fmt.Sprintf(format, args...))
}
}

Expand Down

0 comments on commit 1bbdc90

Please sign in to comment.