@@ -5,17 +5,15 @@ import (
55 "fmt"
66)
77
8- // CustomLogger is a logger interface with leveled logging methods.
9- //
10- // This interface can be implemented by custom loggers to provide leveled logging.
11- type CustomLogger struct {
12- logger LoggerWithLevel
8+ // LoggerWrapper is a slog.Logger wrapper that implements the Lgr interface.
9+ type LoggerWrapper struct {
10+ logger LoggerWithLevelI
1311 loggerLevel * LogLevelT
1412 printfAdapter PrintfAdapter
1513}
1614
17- func NewCustomLogger (logger LoggerWithLevel , opts ... CustomLoggerOption ) * CustomLogger {
18- cl := & CustomLogger {
15+ func NewLoggerWrapper (logger LoggerWithLevelI , opts ... LoggerWrapperOption ) * LoggerWrapper {
16+ cl := & LoggerWrapper {
1917 logger : logger ,
2018 }
2119 for _ , opt := range opts {
@@ -24,16 +22,16 @@ func NewCustomLogger(logger LoggerWithLevel, opts ...CustomLoggerOption) *Custom
2422 return cl
2523}
2624
27- type CustomLoggerOption func (* CustomLogger )
25+ type LoggerWrapperOption func (* LoggerWrapper )
2826
29- func WithPrintfAdapter (adapter PrintfAdapter ) CustomLoggerOption {
30- return func (cl * CustomLogger ) {
27+ func WithPrintfAdapter (adapter PrintfAdapter ) LoggerWrapperOption {
28+ return func (cl * LoggerWrapper ) {
3129 cl .printfAdapter = adapter
3230 }
3331}
3432
35- func WithLoggerLevel (level LogLevelT ) CustomLoggerOption {
36- return func (cl * CustomLogger ) {
33+ func WithLoggerLevel (level LogLevelT ) LoggerWrapperOption {
34+ return func (cl * LoggerWrapper ) {
3735 cl .loggerLevel = & level
3836 }
3937}
@@ -43,15 +41,15 @@ func WithLoggerLevel(level LogLevelT) CustomLoggerOption {
4341type PrintfAdapter func (ctx context.Context , format string , v ... any ) (context.Context , string , []any )
4442
4543// Error is a structured error level logging method with context and arguments.
46- func (cl * CustomLogger ) Error (ctx context.Context , msg string , args ... any ) {
44+ func (cl * LoggerWrapper ) Error (ctx context.Context , msg string , args ... any ) {
4745 if cl == nil || cl .logger == nil {
4846 legacyLoggerWithLevel .Errorf (ctx , msg , args ... )
4947 return
5048 }
5149 cl .logger .ErrorContext (ctx , msg , args ... )
5250}
5351
54- func (cl * CustomLogger ) Errorf (ctx context.Context , format string , v ... any ) {
52+ func (cl * LoggerWrapper ) Errorf (ctx context.Context , format string , v ... any ) {
5553 if cl == nil || cl .logger == nil {
5654 legacyLoggerWithLevel .Errorf (ctx , format , v ... )
5755 return
@@ -60,15 +58,15 @@ func (cl *CustomLogger) Errorf(ctx context.Context, format string, v ...any) {
6058}
6159
6260// Warn is a structured warning level logging method with context and arguments.
63- func (cl * CustomLogger ) Warn (ctx context.Context , msg string , args ... any ) {
61+ func (cl * LoggerWrapper ) Warn (ctx context.Context , msg string , args ... any ) {
6462 if cl == nil || cl .logger == nil {
6563 legacyLoggerWithLevel .Warnf (ctx , msg , args ... )
6664 return
6765 }
6866 cl .logger .WarnContext (ctx , msg , args ... )
6967}
7068
71- func (cl * CustomLogger ) Warnf (ctx context.Context , format string , v ... any ) {
69+ func (cl * LoggerWrapper ) Warnf (ctx context.Context , format string , v ... any ) {
7270 if cl == nil || cl .logger == nil {
7371 legacyLoggerWithLevel .Warnf (ctx , format , v ... )
7472 return
@@ -77,7 +75,7 @@ func (cl *CustomLogger) Warnf(ctx context.Context, format string, v ...any) {
7775}
7876
7977// Info is a structured info level logging method with context and arguments.
80- func (cl * CustomLogger ) Info (ctx context.Context , msg string , args ... any ) {
78+ func (cl * LoggerWrapper ) Info (ctx context.Context , msg string , args ... any ) {
8179 if cl == nil || cl .logger == nil {
8280 legacyLoggerWithLevel .Infof (ctx , msg , args ... )
8381 return
@@ -86,15 +84,15 @@ func (cl *CustomLogger) Info(ctx context.Context, msg string, args ...any) {
8684}
8785
8886// Debug is a structured debug level logging method with context and arguments.
89- func (cl * CustomLogger ) Debug (ctx context.Context , msg string , args ... any ) {
87+ func (cl * LoggerWrapper ) Debug (ctx context.Context , msg string , args ... any ) {
9088 if cl == nil || cl .logger == nil {
9189 legacyLoggerWithLevel .Debugf (ctx , msg , args ... )
9290 return
9391 }
9492 cl .logger .DebugContext (ctx , msg , args ... )
9593}
9694
97- func (cl * CustomLogger ) Infof (ctx context.Context , format string , v ... any ) {
95+ func (cl * LoggerWrapper ) Infof (ctx context.Context , format string , v ... any ) {
9896 if cl == nil || cl .logger == nil {
9997 legacyLoggerWithLevel .Infof (ctx , format , v ... )
10098 return
@@ -103,33 +101,33 @@ func (cl *CustomLogger) Infof(ctx context.Context, format string, v ...any) {
103101 cl .logger .InfoContext (cl .printfToStructured (ctx , format , v ... ))
104102}
105103
106- func (cl * CustomLogger ) Debugf (ctx context.Context , format string , v ... any ) {
104+ func (cl * LoggerWrapper ) Debugf (ctx context.Context , format string , v ... any ) {
107105 if cl == nil || cl .logger == nil {
108106 legacyLoggerWithLevel .Debugf (ctx , format , v ... )
109107 return
110108 }
111109 cl .logger .DebugContext (cl .printfToStructured (ctx , format , v ... ))
112110}
113111
114- func (cl * CustomLogger ) printfToStructured (ctx context.Context , format string , v ... any ) (context.Context , string , []any ) {
112+ func (cl * LoggerWrapper ) printfToStructured (ctx context.Context , format string , v ... any ) (context.Context , string , []any ) {
115113 if cl != nil && cl .printfAdapter != nil {
116114 return cl .printfAdapter (ctx , format , v ... )
117115 }
118116 return ctx , fmt .Sprintf (format , v ... ), nil
119117}
120118
121- func (cl * CustomLogger ) Enabled (ctx context.Context , level LogLevelT ) bool {
119+ func (cl * LoggerWrapper ) Enabled (ctx context.Context , level LogLevelT ) bool {
122120 if cl != nil && cl .loggerLevel != nil {
123121 return level >= * cl .loggerLevel
124122 }
125123
126124 return legacyLoggerWithLevel .Enabled (ctx , level )
127125}
128126
129- // LoggerWithLevel is a logger interface with leveled logging methods.
127+ // LoggerWithLevelI is a logger interface with leveled logging methods.
130128//
131129// [slog.Logger] from the standard library satisfies this interface.
132- type LoggerWithLevel interface {
130+ type LoggerWithLevelI interface {
133131 // InfoContext logs an info level message
134132 InfoContext (ctx context.Context , format string , v ... any )
135133
0 commit comments