-
Notifications
You must be signed in to change notification settings - Fork 160
Closed
Labels
kind/bugSomething isn't workingSomething isn't working
Description
What happened:
When using --template with the function levelColor it prints this error, without the log entry, when encountering level keys it's not familiar with.
expanding template failed: template: log:1:148: executing "log" at <levelColor $d.levelname>: error calling levelColor: runtime error: invalid memory address or nil pointer dereference
What you expected to happen:
I expect the most common level keys to be handled and a fallback to exist instead of generating an error.
How to reproduce it (as minimally and precisely as possible):
Produce "warning" and "critical" logs from a Python application. These two levelnames are not handled.
If stern could read from stdin (I couldn't find that it does at least) it could have looked something like this.
echo '{"levelname": "warning"}' | stern --template='{{with $d := .Message | tryParseJSON}}{{levelColor $d.levelname}}{{end}}{{"\n"}}'Anything else we need to know?:
I'm submitting a PR for this in a moment.
Environment:
- stern version (use
stern --version):
version: 1.24.0
commit: 68305a0ab1383053166b7b606ad167b43fc6b329
built at: 2023-03-12T06:50:44Z
- OS (e.g:
cat /etc/os-release): Arch Linux - Install tools (e.g: Homebrew): Arch AUR https://aur.archlinux.org/packages/stern-bin
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
kind/bugSomething isn't workingSomething isn't working