-
Notifications
You must be signed in to change notification settings - Fork 55
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
flag
#3205
Add --log-level
flag
#3205
Conversation
8f6d522
to
44c499c
Compare
Codecov ReportAttention: Patch coverage is Additional details and impacted files📢 Thoughts on this report? Let us know! |
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.
A few copy paste issues.
crates/core/tedge_mapper/src/lib.rs
Outdated
|
||
let log_level = match log_level { | ||
Some(log_level) => log_level, | ||
None => get_log_level("tedge-agent", &tedge_config_location.tedge_config_root_path)?, |
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.
None => get_log_level("tedge-agent", &tedge_config_location.tedge_config_root_path)?, | |
None => get_log_level("tedge-mapper", &tedge_config_location.tedge_config_root_path)?, |
|
||
let log_level = match log_level { | ||
Some(log_level) => log_level, | ||
None => get_log_level("tedge-agent", &tedge_config_location.tedge_config_root_path)?, |
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.
None => get_log_level("tedge-agent", &tedge_config_location.tedge_config_root_path)?, | |
None => get_log_level("tedge-watchdog", &tedge_config_location.tedge_config_root_path)?, |
|
||
let log_level = match log_level { | ||
Some(log_level) => log_level, | ||
None => get_log_level("tedge-agent", &tedge_config_location.tedge_config_root_path)?, |
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.
None => get_log_level("tedge-agent", &tedge_config_location.tedge_config_root_path)?, | |
None => get_log_level("c8y-firmware-plugin", &tedge_config_location.tedge_config_root_path)?, |
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.
There were 4 places where an identical change was necessary, perhaps we should consider how to extract all the common CLI flags into a shared component.
Could this be implemented in tedge::main.rs
, the multi-call entry for the agent and the mapper?
Flags should always take precedence over environment variable values...generally flags are often used by users to override the environment which they usually have little control over. The first non-empty value should be taken (in order):
|
44c499c
to
62aa224
Compare
Made a dedicated PR that fixes that mistake: #3208
That would probably require some more changes because for every component we use a separate CLI parser, but for now #3208 eliminates some duplication. |
Robot Results
|
Flags should always take precedence over environment variables because are often used by users to override the environment which they usually have little control over. To implement this change it was necessary to refactor the code a little bit as previously set_log_level function was not aware if desired log level was specifically requested by the user (--debug flag) or just the default (INFO level). As such, the new log_init function takes into account all sources that decide what log level we should select: CLI options, RUST_LOG env variable, and tedge configuration file. Signed-off-by: Marcel Guzik <[email protected]>
Signed-off-by: Marcel Guzik <[email protected]>
Add a --log-level flag that sets the verbosity of reported logs. In contrast to --debug, which enables debug logs in addition to the default error, warn, and info logs, --log-level sets the maximum verbosity, i.e. when set to error print only errors, if set to warn print warnings and errors, etc. and when set to trace, print all the logs. If --log-level is selected, this value is used and takes precedence over --debug. RUST_LOG env variable still overrides the flag. Signed-off-by: Marcel Guzik <[email protected]>
62aa224
to
cc41097
Compare
Although, would it be a better user experience to only allow using either |
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.
Approved
Indeed these two flags overlap. But, I don't see that as a big deal. |
Proposed changes
Add a
--log-level
flag that sets the verbosity of reported logs.In contrast to
--debug
, which enables debug logs in addition to the default error, warn, and info logs,--log-level
sets the maximum verbosity, i.e. when set to error print only errors, if set to warn print warnings and errors, etc. and when set to trace, print all the logs.If
--log-level
is selected, this value is used and takes precedence over--debug
.RUST_LOG
env variable still overrides the flag.Types of changes
Paste Link to the issue
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments
There were 4 places where an identical change was necessary, perhaps we should consider how to extract all the common CLI flags into a shared component.Contains a small refactor to logging initialization that eliminates the duplication. Dedicated PR #3208