Skip to content

Commit

Permalink
fix: allow contextKey accepts any type
Browse files Browse the repository at this point in the history
  • Loading branch information
fengccp committed Aug 10, 2024
1 parent d0ef590 commit c392509
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type logger struct {
slowThreshold time.Duration
logLevel map[LogType]slog.Level
gormLevel gormlogger.LogLevel
contextKeys map[string]string
contextKeys map[string]any

sourceField string
errorField string
Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func WithIgnoreTrace() Option {
}

// WithContextValue adds a context value to the log
func WithContextValue(slogAttrName, contextKey string) Option {
func WithContextValue(slogAttrName string, contextKey any) Option {
return func(l *logger) {
if l.contextKeys == nil {
l.contextKeys = make(map[string]string, 0)
l.contextKeys = make(map[string]any, 0)
}
l.contextKeys[slogAttrName] = contextKey
}
Expand Down
2 changes: 1 addition & 1 deletion options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ func TestWithContextValue(t *testing.T) {

WithContextValue(attrName, expected)(actual)

assert.Equal(t, map[string]string{attrName: expected}, actual.contextKeys)
assert.Equal(t, map[string]any{attrName: expected}, actual.contextKeys)
}

0 comments on commit c392509

Please sign in to comment.