Skip to content

Commit

Permalink
fix: fixes log levels that have ansi color by stripping (#3400)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 authored Nov 16, 2024
1 parent 1144bdf commit d4fa7ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion assets/components/LogViewer/ComplexLogItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
<template v-else-if="Array.isArray(value)">
<span class="font-bold" v-html="JSON.stringify(value)"> </span>
</template>
<span class="font-bold" v-html="value" v-else></span>
<span class="font-bold" v-html="stripAnsi(value.toString())" v-else></span>
</li>
<li class="text-light" v-if="Object.keys(validValues).length === 0">all values are hidden</li>
</ul>
</div>
</div>
</template>
<script lang="ts" setup>
import stripAnsi from "strip-ansi";
import { type ComplexLogEntry } from "@/models/LogEntry";
import LogDetails from "./LogDetails.vue";
Expand Down
19 changes: 15 additions & 4 deletions internal/docker/level_guesser.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ func guessLogLevel(logEvent *LogEvent) string {
if value == nil {
return "unknown"
}

if level, ok := value.Get("level"); ok {
if level, ok := level.(string); ok {
return strings.ToLower(level)
return normalizeLogLevel(level)
}
} else if severity, ok := value.Get("severity"); ok {
if severity, ok := severity.(string); ok {
return strings.ToLower(severity)
return normalizeLogLevel(severity)
}
}

Expand All @@ -78,9 +79,9 @@ func guessLogLevel(logEvent *LogEvent) string {
return "unknown"
}
if level, ok := value.Get("level"); ok {
return strings.ToLower(level)
return normalizeLogLevel(level)
} else if severity, ok := value.Get("severity"); ok {
return strings.ToLower(severity)
return normalizeLogLevel(severity)
}

case map[string]interface{}:
Expand All @@ -95,3 +96,13 @@ func guessLogLevel(logEvent *LogEvent) string {

return "unknown"
}

func normalizeLogLevel(level string) string {
level = stripANSI(level)
level = strings.ToLower(level)
if _, ok := SupportedLogLevels[level]; ok {
return level
}

return "unknown"
}

0 comments on commit d4fa7ac

Please sign in to comment.