Skip to content

Commit 865c43a

Browse files
fix: remove colons from level detection (#16764)
1 parent 786f882 commit 865c43a

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

‎pkg/distributor/field_detection.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,21 @@ func isJSON(line string) bool {
306306
}
307307

308308
func detectLevelFromLogLine(log string) string {
309-
if strings.Contains(log, "info:") || strings.Contains(log, "INFO:") ||
310-
strings.Contains(log, "info") || strings.Contains(log, "INFO") {
309+
if strings.Contains(log, "info") || strings.Contains(log, "INFO") {
311310
return constants.LogLevelInfo
312311
}
313-
if strings.Contains(log, "err:") || strings.Contains(log, "ERR:") ||
312+
if strings.Contains(log, "err") || strings.Contains(log, "ERR") ||
314313
strings.Contains(log, "error") || strings.Contains(log, "ERROR") {
315314
return constants.LogLevelError
316315
}
317-
if strings.Contains(log, "warn:") || strings.Contains(log, "WARN:") ||
316+
if strings.Contains(log, "warn") || strings.Contains(log, "WARN") ||
318317
strings.Contains(log, "warning") || strings.Contains(log, "WARNING") {
319318
return constants.LogLevelWarn
320319
}
321-
if strings.Contains(log, "CRITICAL:") || strings.Contains(log, "critical:") {
320+
if strings.Contains(log, "CRITICAL") || strings.Contains(log, "critical") {
322321
return constants.LogLevelCritical
323322
}
324-
if strings.Contains(log, "debug:") || strings.Contains(log, "DEBUG:") {
323+
if strings.Contains(log, "debug") || strings.Contains(log, "DEBUG") {
325324
return constants.LogLevelDebug
326325
}
327326
return constants.LogLevelUnknown

‎pkg/distributor/field_detection_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,41 @@ func Test_detectLogLevelFromLogEntry(t *testing.T) {
277277
},
278278
expectedLogLevel: constants.LogLevelInfo,
279279
},
280+
{
281+
name: "unstructured info log line",
282+
entry: logproto.Entry{
283+
Line: `[INFO] unstructured info log line`,
284+
},
285+
expectedLogLevel: constants.LogLevelInfo,
286+
},
287+
{
288+
name: "unstructured error log line",
289+
entry: logproto.Entry{
290+
Line: `[ERROR] unstructured error log line`,
291+
},
292+
expectedLogLevel: constants.LogLevelError,
293+
},
294+
{
295+
name: "unstructured warn log line",
296+
entry: logproto.Entry{
297+
Line: `[WARN] unstructured warn log line`,
298+
},
299+
expectedLogLevel: constants.LogLevelWarn,
300+
},
301+
{
302+
name: "unstructured critical log line",
303+
entry: logproto.Entry{
304+
Line: `[CRITICAL] unstructured critical log line`,
305+
},
306+
expectedLogLevel: constants.LogLevelCritical,
307+
},
308+
{
309+
name: "unstructured debug log line",
310+
entry: logproto.Entry{
311+
Line: `[DEBUG] unstructured debug log line`,
312+
},
313+
expectedLogLevel: constants.LogLevelDebug,
314+
},
280315
} {
281316
t.Run(tc.name, func(t *testing.T) {
282317
detectedLogLevel := ld.detectLogLevelFromLogEntry(tc.entry, logproto.FromLabelAdaptersToLabels(tc.entry.StructuredMetadata))

0 commit comments

Comments
 (0)