-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Respect config log levels if
--verbosity
not explicitly passed (…
…#5925) The config allows to define the default log level for the logger of the Python API through the `logging.aiida_loglevel` option. The `verdi` CLI provides the `--verbosity` option to control the level of log messages written to console by the command itself, but also by the API code that is called by it. It does so by overriding the `logging.aiida_loglevel` option. The problem was that it was always doing this, even if the `--verbosity` option was not explicitly specified. The reason is that the option defines `REPORT` as the default. This means the callback is always called and so the `CLI_LOG_LEVEL` global would always be set, causing the `configure_logging` to override the config setting with `REPORT`. The solution is to remove the default from the option. If the option is not explicitly defined, the callback receives `None` and it doesn't set the `CLI_LOG_LEVEL`. This change brings a new problem though, as now, when `verdi` is called without `--verbosity` the `configure_logging` will not actually configure the handlers of the `aiida` logger to be the `CliHandler`. To solve this problem, a new global `aiida.common.log.CLI_ACTIVE` is added which is `None` by default. The callback of the verbosity option sets this to `True` to indicate that we are in a `verdi` call. The `configure_logging` will check this global and if set will replace the `console` handler of all loggers to the `cli` handler.` Finally, a new config option `logging.verdi_loglevel` is introduced. This is necessary because since the default for `--verbosity` has been removed, it means the default from `logging.aiida_loglevel` would be taken. However, since this could be set to something higher than `REPORT`, e.g. `WARNING`, it would mean that most of the verdi commands would not print anything, which would suprise a lot of users. The logger used by `aiida.cmdline.utils.echo` is changed from `aiida.cmdline` to `verdi`, to decouple it from the `aiida` logger. Its default log level is defined by the `logging.verdi_loglevel`, which is overridden if a more specific level is set with the `--verbosity` option.
- Loading branch information
Showing
8 changed files
with
122 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.