Skip to content
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

CLI: Only configure logging in set_log_level callback once #6493

Merged
merged 1 commit into from
Jun 28, 2024

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Jun 28, 2024

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.

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.
@sphuber sphuber force-pushed the fix/verdi-logging-configuration branch from fc9383d to 10e2de5 Compare June 28, 2024 14:25
@sphuber sphuber requested a review from GeigerJ2 June 28, 2024 14:25
GeigerJ2

This comment was marked as duplicate.

Copy link
Contributor

@GeigerJ2 GeigerJ2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In @sphuber we trust 🙏🏽

@sphuber sphuber merged commit 66a2dce into aiidateam:main Jun 28, 2024
9 checks passed
@sphuber sphuber deleted the fix/verdi-logging-configuration branch June 28, 2024 14:51
mikibonacci pushed a commit to mikibonacci/aiida-core that referenced this pull request Sep 3, 2024
…am#6493)

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.
Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants