FEniCS / ffcx

Next generation FEniCS Form Compiler for finite element forms
https://fenicsproject.org
Other
145 stars 38 forks source link

[BUG]: `import dolfinx` before logging is setup in the application #567

Closed twmr closed 8 months ago

twmr commented 1 year ago

How to reproduce the bug

If dolfinx is imported before the logging system is configured via e.g. logging.basicConfig, then log messages are not written to stdout.

Minimal Example (Python)

import logging

import dolfinx
print("ABC")
logging.basicConfig(level=logging.DEBUG)
logging.info("DEF")  # this log messages is not written to stdout if dolfinx is imported before the basicConfig call
# If the import is moved after the basicConfig call, then everything works as expected

Output (Python)

ABC

Version

0.6.0

DOLFINx git commit

No response

Installation

No response

Additional information

No response

minrk commented 1 year ago

This is because ffcx itself calls logging.basicConfig at import time, which it probably shouldn't.

Only the first call to logging.basicConfig has any effect.

twmr commented 1 year ago

Thx for the comment! Yes, a logging handler is added by ffcx to the root logger at import time. My subsequent basicConfig call has no effect.

I agree that ffcx shouldn't setup the logging at import time.

Should we move this github issue to the ffcx project?

jorgensd commented 1 year ago

It can have effect if you add force=True to your basicConfig-call. However, I agree that it probably shouldn't be called, and that the issue should be moved to ffcx.