-
Notifications
You must be signed in to change notification settings - Fork 180
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
[Admin] add log level customization command #1362
Conversation
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.
This is essentially just changing log levels. Could we instead use the admin server to perform this change?
Yeeeah, I would actually just crank log level to debug and that's it. |
@huitseeker I considered this too. On one hand, it looks like this should be possible: https://github.com/rs/zerolog#setting-global-log-level On the other hand, not sure if it's actually possible to do this at runtime: rs/zerolog#252 I'll look into this and investigate further. |
Codecov Report
@@ Coverage Diff @@
## master #1362 +/- ##
==========================================
- Coverage 55.29% 55.27% -0.02%
==========================================
Files 516 516
Lines 32181 32185 +4
==========================================
- Hits 17793 17790 -3
- Misses 12001 12007 +6
- Partials 2387 2388 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Looks good. Had some minor suggestion
log = log.Level(zerolog.DebugLevel) | ||
zerolog.SetGlobalLevel(lvl) |
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.
why using debug level as global level?
Better to use InfoLevel
as default
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.
The way this works, is that SetGlobalLevel
sets the minimum level that will be logged, regardless of what the root logger has set.
So, I set the root logger to Debug level, and use SetGlobalLevel
to set the actual level we want to use. This is the only way to make the log level dynamically configurable. I cannot do things the other way around, because once the root logger's level is set, you cannot change it.
Hope this makes sense.
@@ -242,14 +247,15 @@ func (r *CommandRunner) runAdminServer(ctx context.Context) error { | |||
func (r *CommandRunner) runCommand(ctx context.Context, command string, data map[string]interface{}) error { | |||
r.logger.Info().Str("command", command).Msg("received new command") |
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.
better to log the input and output of each command call.
- if it receives a command, it should log
received new command
- if it has run the command, it should log
finish running the command
- if it fails to run the command, it should log
failed to run the command
with the error message.
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.
this will be done in a separate PR :)
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! thanks for putting this together.
bors merge |
Add log level admin command, to allow dynamically changing the log level without restarting a node.
Tested and it works on localnet.
To change the log level to debug, for example:
where
localhost:5873
is the address of the admin server.