aiidateam / aiida-core

The official repository for the AiiDA code
https://aiida-core.readthedocs.io
Other
431 stars 187 forks source link

CLI: Only configure logging in `set_log_level` callback once #6493

Closed sphuber closed 3 months ago

sphuber commented 3 months ago

All verdi commands automatically have the -v/--verbosity option added. This option has a callback set_log_level that is invoked for each subcommand. The callback is supposed to call configure_logging to setup the logging configuration.

Besides it being unnecessary to call it multiple times for each subcommand, it would actually cause a bug in that once the profile storage would have been loaded (through the callback of the profile option), which would have called configure_logging with with_orm=True to make sure the DbLogHandler was properly configured, another call to set_log_level would call configure_logging with the default values (where with_orm=False) and so the DbLogHandler would be removed. This would result in process log messages not being persisted in the database. This would be manifested when running an AiiDA process through a script invoked through verdi or any other CLI that uses the verbosity option provided by aiida-core.

Since the set_log_level only has to make sure that the logging is configured at least once, a guard is added to skip the configuration once the aiida.common.log.CLI_ACTIVE global has been set by a previous invocation.

codecov[bot] commented 5 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 77.77%. Comparing base (ef60b66) to head (10e2de5). Report is 115 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #6493 +/- ## ========================================== + Coverage 77.51% 77.77% +0.26% ========================================== Files 560 561 +1 Lines 41444 41801 +357 ========================================== + Hits 32120 32505 +385 + Misses 9324 9296 -28 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.