Skip to content

Commit e678b61

Browse files
authored
fix: revert remove colons from level detection (#16999)
1 parent 04d2ba3 commit e678b61

2 files changed

Lines changed: 6 additions & 40 deletions

File tree

‎pkg/distributor/field_detection.go‎

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

311311
func detectLevelFromLogLine(log string) string {
312-
if strings.Contains(log, "info") || strings.Contains(log, "INFO") {
312+
if strings.Contains(log, "info:") || strings.Contains(log, "INFO:") ||
313+
strings.Contains(log, "info") || strings.Contains(log, "INFO") {
313314
return constants.LogLevelInfo
314315
}
315-
if strings.Contains(log, "err") || strings.Contains(log, "ERR") ||
316+
if strings.Contains(log, "err:") || strings.Contains(log, "ERR:") ||
316317
strings.Contains(log, "error") || strings.Contains(log, "ERROR") {
317318
return constants.LogLevelError
318319
}
319-
if strings.Contains(log, "warn") || strings.Contains(log, "WARN") ||
320+
if strings.Contains(log, "warn:") || strings.Contains(log, "WARN:") ||
320321
strings.Contains(log, "warning") || strings.Contains(log, "WARNING") {
321322
return constants.LogLevelWarn
322323
}
323-
if strings.Contains(log, "CRITICAL") || strings.Contains(log, "critical") {
324+
if strings.Contains(log, "CRITICAL:") || strings.Contains(log, "critical:") {
324325
return constants.LogLevelCritical
325326
}
326-
if strings.Contains(log, "debug") || strings.Contains(log, "DEBUG") {
327+
if strings.Contains(log, "debug:") || strings.Contains(log, "DEBUG:") {
327328
return constants.LogLevelDebug
328329
}
329330
return constants.LogLevelUnknown

‎pkg/distributor/field_detection_test.go‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -277,41 +277,6 @@ 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-
},
315280
} {
316281
t.Run(tc.name, func(t *testing.T) {
317282
detectedLogLevel := ld.detectLogLevelFromLogEntry(tc.entry, logproto.FromLabelAdaptersToLabels(tc.entry.StructuredMetadata))

0 commit comments

Comments
 (0)