Created
January 3, 2022 22:34
-
-
Save jseguillon/73d739361c73e0908eef193dd19980d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==> json logs <== | |
{"level":"debug","ts":"2021-12-20T19:08:48.053Z","caller":"mvcc/index.go:214","msg":"some debug"} | |
{"level":"info","ts":"2021-12-20T19:03:48.045Z","caller":"mvcc/index.go:214","msg":"maybe be telling something is ok"} | |
{"level":"warning","ts":"2021-12-20T19:03:48.046Z","caller":"mvcc/kvstore_compaction.go:57","msg":"something to notice maybe a failure"} | |
{"level":"error","ts":"2021-12-20T19:08:48.053Z","caller":"mvcc/index.go:214","msg":"a problem because something failed"} | |
==> go logs <== | |
I0103 15:41:04.984104 10819 main.go:278] may indicate something is now running | |
W0103 15:41:06.218155 10819 main.go:130] maybe caused by some xxxBackOff | |
E0103 15:41:06.218155 10819 main.go:130] error maybe also be caused by something failed | |
==> kail logs <== | |
kube/kube[init]: {"component":"component","level":"info","msg":"Starting something."} | |
kube/kube[container]: W1226 00:10:49.722608 1 warnings.go:70] api is deprecated in v1.21+, unavailable in v1.25+; use policy/v1 other | |
==> multitail <== | |
[kube-kube] I0103 14:49:02.480660 1 trace.go:205] Trace[919475402]: something Starting | |
[kube-kube] {"component":"kube-kube","method":"GET","url":"some", "level":"warning"} | |
==> Dockerd <== | |
Jan 03 14:43:55 minikube dockerd[213]: time="2022-01-03T14:43:55.135273900Z" level=info msg="info event" | |
Jan 03 14:44:37 minikube dockerd[213]: time="2022-01-03T14:44:37.310399300Z" level=error msg="some error" | |
Jan 03 14:44:37 minikube dockerd[213]: time="2022-01-03T14:44:37.310399300Z" level=warning msg="some warning" | |
==> journalctl kubelet <== | |
Jan 03 15:34:28 minikube kubelet[1420]: I0103 15:34:28.127473 1420 log.go:184] log | |
Jan 03 15:34:28 minikube kubelet[1420]: W0103 15:34:28.127532 1420 error.go:184] problem | |
Jan 03 15:34:28 minikube kubelet[1420]: E0103 15:34:28.127571 1420 log.go:184] warn | |
I1219 13:39:31.772508 8 nginx.go:255] "Starting NGINX Ingress controller" | |
E1219 13:39:31.772508 8 nginx.go:255] "Killing NGINX Ingress controller" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
awk -F '\n' ' | |
BEGIN{ | |
IGNORECASE=1; x=SUBSEP # shortcut special array split character as 'x' | |
Magenta=35; Blue=34; Yellow=33; Red=31; Green=32; Neutral=0 # Ansi colors | |
# Apply color to whole line if match regex | |
# Use 'x' to separate regular expressions | |
# See README for more explanation and receipes | |
# Kubernetes | |
BlueLinesRegex="\"level\":\"info\"" x " I[0-9]{4} " x "^I[0-9]{4}" x "\\[INFO\\]" | |
YellowLinesRegex="\"level\":\"warning\"" x "\"level\":\"warn\"" x " W[0-9]{4} " x "^W[0-9]{4}" x "\\[WARNING\\]" | |
RedLinesRegex="\"level\":\"error\"" x " E[0-9]{4} " x "^E[0-9]{4}" x "\\[ERROR\\]" | |
# dockerd | |
BlueLinesRegex = BlueLinesRegex x "level=info " | |
YellowLinesRegex = YellowLinesRegex x "level=warning " | |
RedLinesRegex = RedLinesRegex x "level=error " | |
# Apply color + bold effect on regex match separated with 'x' | |
MagentaWordsRegex=" trace" | |
YellowWordsRegex=" deprecated " x " stopping " x " killing " x " killed " | |
RedWordsRegex="failed " x "failure" x "[a-z]*backoff" x "[a-z]*back-off" x "critical" x "[^\"=]error" | |
GreenWordsRegex="running " x "starting" x "started" | |
initAllWordsColors() | |
initAllLinesColors() | |
} | |
{ | |
# Apply color and styles | |
highlight();next | |
} | |
function highlight() { | |
# Get line color if matching plus underline matched regex | |
lc = lineHighlight() | |
# Apply bold style on matched regex words | |
for (marker in ColorWords) { | |
applyStyle(marker, ColorWords[marker], underline(), lc) | |
} | |
# Add color to line and print | |
printf("%s%s\033[0m", color(lc), $0) | |
print "" | |
} | |
# Test whole line and give it a color | |
function lineHighlight() { | |
lc = Neutral | |
for (marker in ColorLines) { | |
if ($0 ~ marker) { | |
lc = ColorLines[marker] | |
applyStyle(marker, ColorLines[marker], bold(), lc); break | |
} | |
} | |
return lc | |
} | |
function applyStyle(marker, newColor, style, prevColor){ | |
# replace matched with color then style, then matched regex ('&' as per awk documentation) | |
# then reset styles and go back to previous color | |
gsub(marker, sprintf("%s%s&%s%s", color(newColor), style, reset(), color(prevColor)), $0) | |
} | |
# Array construction helpers | |
function initAllLinesColors(){ | |
initLineColors(BlueLinesRegex, Blue, x) | |
initLineColors(YellowLinesRegex, Yellow, x) | |
initLineColors(RedLinesRegex, Red, x) | |
} | |
function initAllWordsColors(){ | |
initWordColors(MagentaWordsRegex, Magenta, x) | |
# initWordColors(BlueWordsRegex, Blue, x) | |
initWordColors(YellowWordsRegex, Yellow, x) | |
initWordColors(RedWordsRegex, Red, x) | |
initWordColors(GreenWordsRegex, Green, x) | |
} | |
function initLineColors(markers, color, separator){ | |
split(markers, tmpArray, x) | |
for (i in tmpArray) { ColorLines[tmpArray[i]]=color } | |
} | |
function initWordColors(markers, color, separator){ | |
split(markers, tmpArray, x); | |
for (i in tmpArray) { ColorWords[tmpArray[i]]=color } | |
} | |
# Colors and style helper | |
function color(c) { return sprintf("\033[%dm",c) } | |
function bold() { return sprintf("\033[1m") } | |
function underline() { return sprintf("\033[4m") } | |
function reset() { return sprintf("\033[0;0;0m") } | |
' $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment