Skip to content

Commit

Permalink
adding InfoWithCtx and WarnWithCtx methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jenish-jain committed Mar 31, 2024
1 parent ffd55a6 commit 67eb785
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ type Logger interface {
Debug(log string, args ...any)
DebugWithCtx(ctx context.Context, logMsg string, args ...any)
Info(log string, args ...any)
InfoWithCtx(ctx context.Context, logMsg string, args ...any)
Error(log string, args ...any)
ErrorWithCtx(ctx context.Context, logMsg string, args ...any)
Warn(log string, args ...any)
WarnWithCtx(ctx context.Context, logMsg string, args ...any)
}

type Impl struct {
Expand All @@ -40,13 +42,23 @@ func Info(logMsg string, args ...any) {
log.Info(logMsg, args...)
}

func InfoWithCtx(ctx context.Context, logMsg string, args ...any) {
args = append(args, "request_id", ctx.Value("request_id"))
log.InfoContext(ctx, logMsg, args...)
}

/*
Warn log
*/
func Warn(logMsg string, args ...any) {
log.Warn(logMsg, args...)
}

func WarnWithCtx(ctx context.Context, logMsg string, args ...any) {
args = append(args, "request_id", ctx.Value("request_id"))
log.WarnContext(ctx, logMsg, args...)
}

/*
Error log
*/
Expand Down

0 comments on commit 67eb785

Please sign in to comment.