Skip to content

Commit

Permalink
better log level detection
Browse files Browse the repository at this point in the history
  • Loading branch information
def committed Oct 12, 2023
1 parent f42ad14 commit 6e11bd3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion level.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func GuessLevel(line string) Level {
return r == ']' || r == ')' || r == ';' || r == '|' || r == ':' || r == ',' || r == '.'
})
for _, sf := range subfields {
sf = strings.TrimLeft(strings.ToLower(sf), "\"[('")
sf = strings.TrimLeft(strings.ToLower(sf), "\"[(<'")
sf = strings.TrimPrefix(sf, "level=")
if len(sf) < 4 {
continue
Expand Down
1 change: 1 addition & 0 deletions level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ func TestGuessLevel(t *testing.T) {
assert.Equal(t, LevelError, GuessLevel(`2016-02-04T07:53:57.505612354Z" level=error msg="HTTP Error" err="No such image: -f" statusCode=404`))
assert.Equal(t, LevelDebug, GuessLevel(`[2020-06-25 17:35:37,609][DEBUG][action.search ] [srv] [tweets-100][6]`))
assert.Equal(t, LevelError, GuessLevel(`[2023-10-12T09:56:53.393595+00:00] otel-php.ERROR: Export failure {"exception":"[object] (RuntimeException(code: 0): Export retry limit exceeded at /var/www/vendor/open-telemetry/sdk/Common/Export/Http/PsrTransport.php:114)","source":"OpenTelemetry\\Contrib\\Otlp\\SpanExporter"} []`))
assert.Equal(t, LevelWarning, GuessLevel(`2023.10.12 13:58:41.168802 [ 847 ] {} <Warning> TCPHandler: Using deprecated interserver protocol because the client is too old. Consider upgrading all nodes in cluster.`))
}

0 comments on commit 6e11bd3

Please sign in to comment.