Conversation
8f6d522 to
44c499c
Compare
Codecov ReportAttention: Patch coverage is Additional details and impacted files📢 Thoughts on this report? Let us know! |
albinsuresh
left a comment
There was a problem hiding this comment.
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.
| 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.
| 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.
| 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)?, |
didier-wenzek
left a comment
There was a problem hiding this comment.
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 <marcel.guzik@inetum.com>
Signed-off-by: Marcel Guzik <marcel.guzik@inetum.com>
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 <marcel.guzik@inetum.com>
62aa224 to
cc41097
Compare
|
Although, would it be a better user experience to only allow using either |
Indeed these two flags overlap. But, I don't see that as a big deal. |
Proposed changes
Add a
--log-levelflag 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-levelsets 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-levelis selected, this value is used and takes precedence over--debug.RUST_LOGenv variable still overrides the flag.Types of changes
Paste Link to the issue
Checklist
cargo fmtas mentioned in CODING_GUIDELINEScargo clippyas 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