Skip to content

Commit

Permalink
fix: add detected_level info when the info word appears on log message (
Browse files Browse the repository at this point in the history
  • Loading branch information
yduartep authored Jun 14, 2024
1 parent e7689b2 commit c9bfa3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,10 @@ func isJSON(line string) bool {
}

func detectLevelFromLogLine(log string) string {
if strings.Contains(log, "info:") || strings.Contains(log, "INFO:") ||
strings.Contains(log, "info") || strings.Contains(log, "INFO") {
return logLevelInfo
}
if strings.Contains(log, "err:") || strings.Contains(log, "ERR:") ||
strings.Contains(log, "error") || strings.Contains(log, "ERROR") {
return logLevelError
Expand Down
14 changes: 14 additions & 0 deletions pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,20 @@ func Test_detectLogLevelFromLogEntry(t *testing.T) {
},
expectedLogLevel: logLevelError,
},
{
name: "json log line with an INFO in block case",
entry: logproto.Entry{
Line: `{"foo":"bar","msg":"message with keyword INFO get picked up"}`,
},
expectedLogLevel: logLevelInfo,
},
{
name: "logfmt log line with an INFO and not level returns info log level",
entry: logproto.Entry{
Line: `foo=bar msg="message with info and not level should get picked up"`,
},
expectedLogLevel: logLevelInfo,
},
{
name: "logfmt log line with a warn",
entry: logproto.Entry{
Expand Down

0 comments on commit c9bfa3e

Please sign in to comment.