-
Notifications
You must be signed in to change notification settings - Fork 454
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
Allow to change log level for server. #346
Conversation
Add possobility to change output verbosity via environment varaible `LOG_LEVEL`. There are several values: panic, fatal, error, warn or warning, info, debug and trace. By default `info` is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we try to use logrus level as default instead of string?
cmd/server/server.go
Outdated
@@ -42,3 +46,18 @@ func main() { | |||
|
|||
server.Listen(host, port) | |||
} | |||
|
|||
const LOG_LEVEL_DEFAULT = "info" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call it DEFAULT_LOG_LEVEL
?
const LOG_LEVEL_DEFAULT = "info" | |
const DEFAULT_LOG_LEVEL = logrus.InfoLevel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - one typo but the rest is optional.
Seeing "config file" in the diff, I wondered about why this was an environment variable instead of part of the config. I grok that the configuration is rooted as an array, so there's no nice place to add a "global" configuration option. Environment variables make sense!
cmd/server/server.go
Outdated
if ok { | ||
lvl, err := logrus.ParseLevel(val) | ||
if err != nil { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: is err
is worth logging here, perhaps at .Error()
?
Since we used LookupEnv
, we know the user provided a LOG_LEVEL
value. They may want feedback if that value was incorrect:
err
will give themnot a valid logrus Level: FOO_BAR
- Overkill, but you could build a message from
logrus.AllLevels
to include what levels are accepted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thepwagner Updated the code to print error message in case the LOG_LEVEL is not valid.
Co-authored-by: Pete Wagner <1559510+thepwagner@users.noreply.github.com>
Co-authored-by: Pete Wagner <1559510+thepwagner@users.noreply.github.com>
Add possobility to change output verbosity via environment varaible
LOG_LEVEL
. There are several values: panic, fatal, error, warn orwarning, info, debug and trace.
By default
info
is used.close: #343