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

Ensure logging messages don't reach the root logger #345

Merged
merged 3 commits into from
Jan 19, 2024

Conversation

hugobuddel
Copy link
Collaborator

DEBUG should only be used when, well, debugging, and is thus not useful to have on by default.

DEBUG should only be used when, well, debugging, and is thus not
useful to have on by default.
Copy link

codecov bot commented Jan 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2c7a0f0) 75.52% compared to head (42a9ed8) 75.53%.
Report is 2 commits behind head on dev_master.

Additional details and impacted files
@@             Coverage Diff             @@
##           dev_master     #345   +/-   ##
===========================================
  Coverage       75.52%   75.53%           
===========================================
  Files              59       59           
  Lines            7870     7871    +1     
===========================================
+ Hits             5944     5945    +1     
  Misses           1926     1926           

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

@teutoburg
Copy link
Contributor

teutoburg commented Jan 19, 2024

There's a difference between the level of the logger and that of the handler. The console handler is set to INFO by default, so the DEBUG level messages should not get through! I'll investigate a bit more to understand why it's apparently still happening.

@teutoburg
Copy link
Contributor

It seems the (outdated but not yet removed) root logging call in the @add_function_call_str decorator in scopesim_templates is somehow adding a handler to the root logger. Not sure if that's what happened in Gilles' case, but it's certainly a way to get this bug. I had another PR in the making that would mitigate that in a more robust way, by setting propagate=False for the astar logger. But I got distracted from finishing that.

Anyway, I do understand what the purpose of DEBUG is and it was never my intent to display DEBUG level messages to the user by default!

scopesim/__init__.py Outdated Show resolved Hide resolved
Co-authored-by: teutoburg <73600109+teutoburg@users.noreply.github.com>
@teutoburg
Copy link
Contributor

Interesting, now the tests fail on the Quantization effect which I introduced recently. The "captured output" shows that those warnings are there though...

@teutoburg
Copy link
Contributor

Maybe because the logging configuration is not (correctly) applied in the tests? I can attempt to fix it and then push to this PR if that's ok with you

@hugobuddel
Copy link
Collaborator Author

Now test_logs_warning_for_float_dtype() fails:

>       assert "Setting quantized data to dtype" in caplog.text
E       AssertionError: assert 'Setting quantized data to dtype' in ''
E        +  where '' = <_pytest.logging.LogCaptureFixture object at 0x00000173002FEE10>.text

I think I don't understand how logging works... let me try to summarize:

  • top_logger has loglevel Warning, this level is (apparently) tested in test_logs_warning_for_float_dtype()
    • child sim_logger is set to Debug, this (apparently) causes all debug info to be printed (at least in a notebook)
    • each module has its own child from top_logger, which somehow both gets the Warning level from top_logger (see failing test) as well as the Debug level from sim_logger, see output in notebooks

Then there are two handlers that are attached to the top_logger

  • one for output to a file, which gets level Debug, I suppose this one is 'invisible' to the issue at hand
  • one for output to stdout, which gets level Info, but not sure how this comes into play

I don't understand how the Debug info gets into the notebook before this PR, nor why the test fails for this PR.

By the way, I figured you understood what the levels are for; setting the Debug level was done long ago, not sure whether it was also visible in the past though.

@hugobuddel
Copy link
Collaborator Author

Maybe because the logging configuration is not (correctly) applied in the tests? I can attempt to fix it and then push to this PR if that's ok with you

Yeah that's fine. I didn't expect this to be so involved; I thought it was just an outdated loglevel setting that we never got to change

@hugobuddel
Copy link
Collaborator Author

Everything seems to work as intended now I think.

The notebooks etc do not show the debug information anymore.

@hugobuddel
Copy link
Collaborator Author

The output in the notebooks now looks identical to the output before #339 .

I also verified that it is still possible to set the loglevel to DEBUG through ~/.scopesim_rc.yaml. I was a bit afraid that disabling the propagation would prevent that.

Maybe when we setup nightly runs of the notebooks (and other tests, and bulk simulations), we could automatically generate diffs with the previous night, to catch unexpected problems.

Shall we merge this?

@teutoburg
Copy link
Contributor

I thought it was just an outdated loglevel setting that we never got to change

It was something I introduced in the recent logging changes. The previous setting was WARNING by default, which was also what Oliver complained about in #257. It worked fine (i.e., no DEBUG by default) when I tested it, but I didn't test the case that there might be a plain logging.debug() call somewhere outside scopesim, which I should have. Had I had the time to continue with the dict config, we most likely would have never noticed, because that includes the same propagate: False. But this way, I at least learned even more about how logging works, which is a positive.

@teutoburg
Copy link
Contributor

This was also useful in the scope of the tests, because 42a9ed8 now also fixes the huge log spam that was sometimes seen in the tests.

@teutoburg teutoburg changed the title Set loglevel to INFO by default Ensure logging messages don't reach the root logger Jan 19, 2024
@teutoburg
Copy link
Contributor

Changed the title to more closely reflect what's actually going on 🙃

@teutoburg
Copy link
Contributor

Maybe when we setup nightly runs of the notebooks (and other tests, and bulk simulations), we could automatically generate diffs with the previous night, to catch unexpected problems.

The notebook plugin for pytest has a feature that does something like that, it's on my TODO to investigate this anyway...

@teutoburg teutoburg merged commit 39e3f54 into dev_master Jan 19, 2024
24 checks passed
@teutoburg teutoburg deleted the hb/loglevelinfobydefault branch January 19, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants