Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log level color keys and handle default #264

Merged
merged 2 commits into from May 5, 2023

Conversation

hogklint
Copy link
Contributor

@hogklint hogklint commented May 3, 2023

This PR intends to solve issue #263 by handling two more common log-level keys as well as handling the fallback case so that an error is never printed. The two new keys are used in Python's logging facilities.

I didn't find a way to add custom log-level keys as a user, but I think this works well. It would be very appreciated if it didn't cause an error at least.

Test by using stern to print logs from a Python application that emits "warning" and "critical" logs. Preferably also test with an unknown key

echo '{"levelname": "invalid key"}' | stern --template='{{with $d := .Message | tryParseJSON}}{{levelColor $d.levelname}}{{end}}{{"\n"}}'

Also adding a default white color when the key is not recognize. Without
the default an error is printed instead of the log entry.
cmd/cmd.go Outdated Show resolved Hide resolved
Co-authored-by: Takashi Kusumi <tkusumi@zlab.co.jp>
@hogklint hogklint requested a review from tksm May 5, 2023 07:39
Copy link
Contributor

@tksm tksm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks for your PR!

@tksm tksm merged commit 65204cc into stern:master May 5, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants