Add log level color keys and handle default (#264) · stern/stern@65204cc · GitHub
Skip to content

Commit

Permalink
Add log level color keys and handle default (#264)
Browse files Browse the repository at this point in the history
* Add log level color keys

Also adding a default white color when the key is not recognize. Without
the default an error is printed instead of the log entry.

* Fallback to default terminal color on unknown log level

Co-authored-by: Takashi Kusumi <tkusumi@zlab.co.jp>

---------

Co-authored-by: Takashi Kusumi <tkusumi@zlab.co.jp>
  • Loading branch information
hogklint and tksm authored May 5, 2023
1 parent d7d5a4f commit 65204cc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ func (o *options) generateTemplate() (*template.Template, error) {
levelColor = color.New(color.FgBlue)
case "warn":
levelColor = color.New(color.FgYellow)
case "warning":
levelColor = color.New(color.FgYellow)
case "error":
levelColor = color.New(color.FgRed)
case "dpanic":
Expand All @@ -494,7 +496,10 @@ func (o *options) generateTemplate() (*template.Template, error) {
levelColor = color.New(color.FgRed)
case "fatal":
levelColor = color.New(color.FgCyan)
case "critical":
levelColor = color.New(color.FgCyan)
default:
return level
}
return levelColor.SprintFunc()(level)
},
Expand Down

0 comments on commit 65204cc

Please sign in to comment.