Skip to content

Instantly share code, notes, and snippets.

@manios
Last active May 28, 2024 06:33
Show Gist options
  • Save manios/cbe52788142bfa19b345b9bddbde4cca to your computer and use it in GitHub Desktop.
Save manios/cbe52788142bfa19b345b9bddbde4cca to your computer and use it in GitHub Desktop.
Stern template to format Spring Boot json logs into normal slf4j lockback text in Kubernetes. Used in https://manios.org/2023/06/18/kubernetes-view-pod-json-log-in-plain-text-with-stern-template
{{ printf "%-35s " .PodName -}}
{{ with $d := .Message | tryParseJSON -}}
{{ $myMessage := "" -}}
{{ $myStackTrace := "" -}}
{{ if $d.message -}}
{{ $myMessage = $d.message -}}
{{ end -}}
{{ if $d.stack_trace -}}
{{ $myStackTrace = $d.stack_trace -}}
{{ end -}}
{{ printf "%s %v %6.6s --- [%15.15s] %-70s : %s %s" (index $d "@timestamp") $d.level_value $d.level $d.thread_name $d.logger_name $myMessage $myStackTrace }}{{else}}{{ .Message }}{{"\n"}}{{end}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment