Skip to content

Commit

Permalink
feature: WS-512 Add support for tagged logs by extracting fields from…
Browse files Browse the repository at this point in the history
… arguments
  • Loading branch information
akeemphilbert committed Mar 16, 2024
1 parent 2eaa57b commit bd2b897
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ func (z *Zap) Errorf(format string, args ...interface{}) {
}

func (z *Zap) Error(args ...interface{}) {
fields, _ := z.extractTags(args...)
z.SugaredLogger.Error(fields...)
fields, arguments := z.extractTags(args...)
if len(fields) > 0 {
z.SugaredLogger.With(fields...)
}
z.SugaredLogger.Error(arguments...)
}

func (z *Zap) Warnf(format string, args ...interface{}) {
Expand All @@ -103,8 +106,11 @@ func (z *Zap) Warnf(format string, args ...interface{}) {
}

func (z *Zap) Warn(args ...interface{}) {
fields, _ := z.extractTags(args...)
z.SugaredLogger.Error(fields...)
fields, arguments := z.extractTags(args...)
if len(fields) > 0 {
z.SugaredLogger.With(fields...)
}
z.SugaredLogger.Warn(arguments...)
}

func (z *Zap) Debugf(format string, args ...interface{}) {
Expand All @@ -116,8 +122,11 @@ func (z *Zap) Debugf(format string, args ...interface{}) {
}

func (z *Zap) Debug(args ...interface{}) {
fields, _ := z.extractTags(args...)
z.SugaredLogger.Error(fields...)
fields, arguments := z.extractTags(args...)
if len(fields) > 0 {
z.SugaredLogger.With(fields...)
}
z.SugaredLogger.Debug(arguments...)
}

func (z *Zap) Output() io.Writer {
Expand Down

0 comments on commit bd2b897

Please sign in to comment.