Skip to content

Commit

Permalink
Add support for .With() to CLoggers (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufnitza authored Jan 4, 2023
1 parent 2282204 commit 64eaa15
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,27 @@ func (l *CSugaredLogger) WithContextCorrelationId(ctx context.Context) *CSugared
// WithCorrelationId returns an instance of the same logger with the correlation ID field added to it.
func (l *CLogger) WithCorrelationId(correlationId interface{}) *CLogger {
if s, ok := correlationId.(string); ok {
return &CLogger{*l.With(zap.Stringp(correlationIdFieldKey, &s))}
return &CLogger{*l.Logger.With(zap.Stringp(correlationIdFieldKey, &s))}
}
return l
}

// WithCorrelationId returns an instance of the same logger with the correlation ID field added to it.
func (l *CSugaredLogger) WithCorrelationId(correlationId interface{}) *CSugaredLogger {
if s, ok := correlationId.(string); ok {
return &CSugaredLogger{*l.With(zap.Stringp(correlationIdFieldKey, &s))}
return &CSugaredLogger{*l.SugaredLogger.With(zap.Stringp(correlationIdFieldKey, &s))}
}
return l
}

func (l *CLogger) With(args ...zap.Field) *CLogger {
return &CLogger{*l.Logger.With(args...)}
}

func (l *CSugaredLogger) With(args ...interface{}) *CSugaredLogger {
return &CSugaredLogger{*l.SugaredLogger.With(args...)}
}

// SugaredLogger returns an instance of the sugared logger. You must have initialized the logger prior to this call.
func SugaredLogger() *CSugaredLogger {
if logger == nil {
Expand Down Expand Up @@ -193,15 +201,15 @@ func Init(ctx context.Context, enableLogLevelEndpoint, developmentMode bool) {
}

func (l *CSugaredLogger) Print(args ...interface{}) {
l.Debug(args)
l.Debug(args...)
}

func (l *CSugaredLogger) Println(args ...interface{}) {
l.Debug(args)
l.Debug(args...)
}

func (l *CSugaredLogger) Printf(format string, args ...interface{}) {
l.Debugf(format, args)
l.Debugf(format, args...)
}

func (l *CSugaredLogger) Fatalln(args ...interface{}) {
Expand Down

0 comments on commit 64eaa15

Please sign in to comment.