8000 [MRG] Reduce logging for missing imports by scaramallion · Pull Request #2129 · pydicom/pydicom · GitHub
[go: up one dir, main page]

Skip to content

Conversation

scaramallion
Copy link
Member
@scaramallion scaramallion commented Sep 9, 2024

Describe the changes

Tasks

  • Unit tests added that reproduce the issue or prove feature is working
  • Fix or feature added
  • Code typed and mypy shows no errors
  • Documentation updated (if relevant)
  • Unit tests passing and overall coverage the same or better

Copy link
codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.38%. Comparing base (b2073cc) to head (f2797a0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2129      +/-   ##
==========================================
+ Coverage   98.34%   98.38%   +0.04%     
==========================================
  Files          77       77              
  Lines       13435    13435              
==========================================
+ Hits        13212    13218       +6     
+ Misses        223      217       -6     

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

@scaramallion scaramallion changed the title [WIP] Reduce logging for missing imports [MRG] Reduce logging for missing imports Sep 10, 2024
except Exception as exc:
LOGGER.exception(exc)
if config.debugging:
LOGGER.warning(exc)
Copy link
Member

Choose a reason for hiding this comment

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

Why not just use LOGGER.debug() here? Generally, I wonder why we need that config.debugging at all, if it just means the logging level is DEBUG.

Copy link
Member Author
@scaramallion scaramallion Sep 10, 2024

Choose a reason for hiding this comment

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

Mostly because you suggested warning 😛. Technically config.debugging just enables extra logging (especially in frequently used code), not necessarily debug logging.

One thing I'd like to do for 3.1 is improve the overall logging.

8000

Copy link
Member

Choose a reason for hiding this comment

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

Mostly because you suggested warning

Did I? Silly me...

Technically config.debugging just enables extra logging (especially in frequently used code), not necessarily debug logging.

Hm, isn't that what log levels are for? We don't use info at all, I think...

One thing I'd like to do for 3.1 is improve the overall logging.

🚀

debugging = False


# force level=WARNING, in case logging default is set differently (issue 103)
Copy link
Member

Choose a reason for hiding this comment

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

I wanted to ask how you dug up a ten-year-old issue before I noticed that the code just had been moved :)

module = importlib.import_module(package_name, "__version__")
return tuple(int(x) for x in module.__version__.split(".")) >= minimum_version
except Exception as exc:
if config.debugging:
Copy link
Member

Choose a reason for hiding this comment

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

Still the same question: why do you need to check for config.debugging here (or elsewhere)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's probably not as useful here, but in the data_element_generator code especially it's used to prevent logging in heavily used parts of the code base, presumably for efficiency.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, that makes some sense, though I would still argue that this could be just debug logging.

Copy link
Member

Choose a reason for hiding this comment

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

It's probably not as useful here, but in the data_element_generator code especially it's used to prevent logging in heavily used parts of the code base, presumably for efficiency.

This. Could probably do it by checking the debug level as well, but actually calling LOGGING.debug() would be an "expensive" function call regardless of logging level. An if statement is much faster.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see. Actually, checking the debug level ist the first thing that the logger does, but it is of course more expansive than the if statement. Also, we would have to make sure, that we don't do anything expansive in the log message that will evaluated during the call.
So this is actually an optimization that can be used in critical code paths.

@scaramallion scaramallion merged commit 2703297 into pydicom:main Sep 13, 2024
10 checks passed
@scaramallion scaramallion deleted the fix-import-logging branch September 13, 2024 03:53
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.

Pydicom 3.0 and "No module named 'openjpeg' nor 'jpeg_ls'" error
3 participants
0