Skip to content

Commit

Permalink
fix levelSeverity logic
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpionknifes committed Apr 9, 2024
1 parent 232a4fb commit 24246eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 2 additions & 7 deletions bridges/otellogr/logsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,12 @@ func (l *LogSink) Enabled(level int) bool {

// Error logs an error, with the given message and key/value pairs.
func (l *LogSink) Error(err error, msg string, keysAndValues ...any) {
const severity = log.SeverityError

l.log(err, msg, severity, keysAndValues...)
l.log(err, msg, log.SeverityError, keysAndValues...)
}

// Info logs a non-error message with the given key/value pairs.
func (l *LogSink) Info(level int, msg string, keysAndValues ...any) {
const sevOffset = int(log.SeverityInfo)
severity := log.Severity(sevOffset + level)

l.log(nil, msg, severity, keysAndValues...)
l.log(nil, msg, l.levelSeverity(level), keysAndValues...)
}

// Init receives optional information about the logr library this
Expand Down
5 changes: 5 additions & 0 deletions bridges/otellogr/logsink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ func TestNewLogSinkConfiguration(t *testing.T) {
ls = NewLogSink(
WithLoggerProvider(r),
WithInstrumentationScope(wantScope),
WithLevelSeverity(func(i int) log.Severity {
return log.SeverityFatal
}),
)
})
assert.NotNil(t, ls)
require.IsType(t, &recorder{}, ls.logger)
assert.NotNil(t, ls.levelSeverity)
assert.Equal(t, log.SeverityFatal, ls.levelSeverity(0))

l := ls.logger.(*recorder)
assert.Equal(t, wantScope, l.Scope)
Expand Down

0 comments on commit 24246eb

Please sign in to comment.