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

Fix logging yet again #599

Merged
merged 18 commits into from
Sep 23, 2020
Merged

Fix logging yet again #599

merged 18 commits into from
Sep 23, 2020

Conversation

kba
Copy link
Member

@kba kba commented Sep 11, 2020

This PR is an attempt to fix a lot of code smell related to logging.

  • getLogger will raise an exception if initLogging was never called before getLogger before initLogging will emit CRITICAL log messages about that fact and the file/line where it originated
  • setOverrideLogLevel can now happen before initLogging (cmdline loglevel override does not work anymore #597)
  • new method disableLogging which requires a new initLogging call and resets override loglevel
  • no longer set the loglevel of the root logger to logging.NOTSET
  • no more module-level loggers - use method-specific loggers (which can re-use the same name of course)
  • use the first config file found xor the builtin config. setOverrideLoglevel should take precedent over either.

Since logging happens in many places, PR is probably better digestable commit-by-commit.

@kba kba requested a review from bertsky September 11, 2020 18:23
Copy link
Collaborator

@bertsky bertsky left a comment

Choose a reason for hiding this comment

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

This clearly moves into a good direction. I must confess though that I do not grasp this fully. For example, I don't get why reinit=True is necessary for each initLogging call in the various CLIs. (Shouldn't the overrideLogLevel be restricted to only set the global variable for getLogger, and unset any existing log levels?)

Note that in my review I went through each commit individually, so some of the comments don't apply after a later commit anymore.

ocrd_utils/ocrd_utils/logging.py Outdated Show resolved Hide resolved
ocrd_utils/ocrd_utils/logging.py Outdated Show resolved Hide resolved
ocrd_utils/ocrd_utils/logging.py Outdated Show resolved Hide resolved
ocrd_utils/ocrd_utils/logging.py Show resolved Hide resolved
ocrd_utils/ocrd_utils/logging.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2020

Codecov Report

Merging #599 into master will increase coverage by 0.04%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #599      +/-   ##
==========================================
+ Coverage   84.88%   84.93%   +0.04%     
==========================================
  Files          52       52              
  Lines        2892     2934      +42     
  Branches      565      570       +5     
==========================================
+ Hits         2455     2492      +37     
- Misses        328      332       +4     
- Partials      109      110       +1     
Impacted Files Coverage Δ
ocrd/ocrd/cli/zip.py 66.66% <0.00%> (-2.23%) ⬇️
ocrd_utils/ocrd_utils/__init__.py 100.00% <ø> (ø)
...d_validators/ocrd_validators/ocrd_zip_validator.py 100.00% <ø> (ø)
ocrd_utils/ocrd_utils/logging.py 85.13% <77.14%> (-3.55%) ⬇️
ocrd/ocrd/cli/workspace.py 76.55% <80.00%> (ø)
ocrd/ocrd/workspace.py 69.40% <88.88%> (+0.36%) ⬆️
ocrd/ocrd/cli/log.py 92.00% <100.00%> (+0.69%) ⬆️
ocrd/ocrd/cli/process.py 92.85% <100.00%> (+14.28%) ⬆️
ocrd/ocrd/cli/validate.py 100.00% <100.00%> (ø)
ocrd/ocrd/decorators/__init__.py 88.57% <100.00%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5bafa53...7e40ab6. Read the comment docs.

ocrd_utils/ocrd_utils/logging.py Outdated Show resolved Hide resolved
ocrd_utils/ocrd_utils/logging.py Outdated Show resolved Hide resolved
@kba kba requested a review from bertsky September 22, 2020 10:27
Copy link
Collaborator

@bertsky bertsky left a comment

Choose a reason for hiding this comment

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

We are nearly there (if not already) IMO.

ocrd_utils/ocrd_utils/logging.py Outdated Show resolved Hide resolved
ocrd_utils/ocrd_utils/logging.py Show resolved Hide resolved
@bertsky bertsky self-requested a review September 23, 2020 13:10
Copy link
Collaborator

@bertsky bertsky left a comment

Choose a reason for hiding this comment

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

Great work! (So OCR-D finally has a truly commendable and Pythonic logging system, both functionally and by implementation.)

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.

3 participants