Deltares / hydromt

HydroMT: Automated and reproducible model building and analysis
https://deltares.github.io/hydromt/
MIT License
65 stars 28 forks source link

Multiple handlers point towards the same file when logging #1006

Closed Jaapel closed 1 week ago

Jaapel commented 2 weeks ago

HydroMT version checks

Reproducible Example

test_cli_build_override produces exceptions on windows.

Current behaviour

In ModelRoot and in multiple functions in cli.main a FileHandler for logging is created, pointing to the same file. Logging is passed through (almost) every method and function in HydroMT as a keyword argument.

Desired behaviour

Use logging as intended by creating a hierarchy and getting a logger using getLogger(__name__). No need to pass loggers around.

Additional context

No response

Jaapel commented 2 weeks ago

https://docs.python.org/3/howto/logging-cookbook.html#opening-the-same-log-file-multiple-times https://docs.python.org/3/howto/logging-cookbook.html#using-loggers-as-attributes-in-a-class-or-passing-them-as-parameters

Jaapel commented 1 week ago

Still struggling with logging during tests. Reproduce with:

pixi run -e full-py311 pytest tests/cli/test_cli.py::test_cli_build_override tests/components/test_grid_component.py::test_add_data_from_rasterdataset --ff --pdb