Skip to content

Commit

Permalink
fix(zap): only record log metrics when we actually log something (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
tessig authored Jul 13, 2023
1 parent f616b5e commit b0dca2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/silentzap/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func makeFieldMap(configFieldMap config.Map) map[string]string {
}

func (l *SilentLogger) record(level string) {
if !l.Core().Enabled(logLevels[level]) {
return
}

ctx, _ := tag.New(context.Background(), tag.Upsert(opencensus.KeyArea, l.configArea), tag.Upsert(keyLevel, level))
stats.Record(ctx, logCount.M(1))
}
Expand Down
4 changes: 4 additions & 0 deletions core/zap/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func (l *Logger) WithContext(ctx context.Context) flamingo.Logger {
}

func (l *Logger) record(level string) {
if !l.Core().Enabled(logLevels[level]) {
return
}

ctx, _ := tag.New(context.Background(), tag.Upsert(opencensus.KeyArea, l.configArea), tag.Upsert(keyLevel, level))
stats.Record(ctx, logCount.M(1))
}
Expand Down

0 comments on commit b0dca2b

Please # to comment.