Skip to content

Fix logging yet again#599

Merged
kba merged 18 commits intomasterfrom
fix-logging-yet-again
Sep 23, 2020
Merged

Fix logging yet again#599
kba merged 18 commits intomasterfrom
fix-logging-yet-again

Conversation

@kba
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread ocrd_utils/ocrd_utils/logging.py Outdated
Comment thread ocrd_utils/ocrd_utils/logging.py Outdated
Comment thread ocrd_utils/ocrd_utils/logging.py Outdated
Comment thread ocrd_utils/ocrd_utils/logging.py
Comment thread ocrd_utils/ocrd_utils/logging.py Outdated
@codecov-commenter
Copy link
Copy Markdown

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.

Comment thread ocrd_utils/ocrd_utils/logging.py Outdated
Comment thread ocrd_utils/ocrd_utils/logging.py Outdated
@kba kba requested a review from bertsky September 22, 2020 10:27
Copy link
Copy Markdown
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.

Comment thread ocrd_utils/ocrd_utils/logging.py Outdated
Comment thread ocrd_utils/ocrd_utils/logging.py
@bertsky bertsky self-requested a review September 23, 2020 13:10
Copy link
Copy Markdown
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