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

Add skip call when logging with fields at all levels #1

Merged
merged 2 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions examples/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ encoders:
- timestamp:
format: ISO8601
- caller #:
#format: short
#format: short
#- stacktrace
json:
fields:
Expand Down Expand Up @@ -44,4 +44,4 @@ rootLogger:
outputs:
- stdout:
level: info
- file
- file
2 changes: 1 addition & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ var log = dazl.GetPackageLogger()
const projectName = "dazl"

func main() {
log.Infof("%s is a logging framework for Go", projectName)
log.Infow("dazl is a logging framework for Go", dazl.String("foo", "bar"))
}
12 changes: 6 additions & 6 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func (l *dazlLogger) Debugf(format string, args ...any) {
}

func (l *dazlLogger) Debugw(msg string, fields ...Field) {
l.WithFields(fields...).Debug(msg)
l.WithFields(fields...).WithSkipCalls(1).Debug(msg)
}

func (l *dazlLogger) Info(args ...any) {
Expand All @@ -490,7 +490,7 @@ func (l *dazlLogger) Infof(format string, args ...any) {
}

func (l *dazlLogger) Infow(msg string, fields ...Field) {
l.WithFields(fields...).Info(msg)
l.WithFields(fields...).WithSkipCalls(1).Info(msg)
}

func (l *dazlLogger) Warn(args ...any) {
Expand All @@ -510,7 +510,7 @@ func (l *dazlLogger) Warnf(format string, args ...any) {
}

func (l *dazlLogger) Warnw(msg string, fields ...Field) {
l.WithFields(fields...).Warn(msg)
l.WithFields(fields...).WithSkipCalls(1).Warn(msg)
}

func (l *dazlLogger) Error(args ...any) {
Expand All @@ -530,7 +530,7 @@ func (l *dazlLogger) Errorf(format string, args ...any) {
}

func (l *dazlLogger) Errorw(msg string, fields ...Field) {
l.WithFields(fields...).Error(msg)
l.WithFields(fields...).WithSkipCalls(1).Error(msg)
}

func (l *dazlLogger) Fatal(args ...any) {
Expand All @@ -550,7 +550,7 @@ func (l *dazlLogger) Fatalf(format string, args ...any) {
}

func (l *dazlLogger) Fatalw(msg string, fields ...Field) {
l.WithFields(fields...).Fatal(msg)
l.WithFields(fields...).WithSkipCalls(1).Fatal(msg)
}

func (l *dazlLogger) Panic(args ...any) {
Expand All @@ -570,7 +570,7 @@ func (l *dazlLogger) Panicf(format string, args ...any) {
}

func (l *dazlLogger) Panicw(msg string, fields ...Field) {
l.WithFields(fields...).Panic(msg)
l.WithFields(fields...).WithSkipCalls(1).Panic(msg)
}

var _ Logger = &dazlLogger{}
Expand Down
1 change: 1 addition & 0 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func TestLoggerMethods(t *testing.T) {
}))

stdout.EXPECT().WithName(gomock.Eq("test")).Return(stdout)
stdout.EXPECT().WithSkipCalls(gomock.Eq(1)).Return(stdout).AnyTimes()
log := GetLogger("test")

stdout.EXPECT().Debug(gomock.Eq("debug"))
Expand Down