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

Set only one handler for logging in k4run #192

Merged
merged 1 commit into from
Apr 25, 2024
Merged

Set only one handler for logging in k4run #192

merged 1 commit into from
Apr 25, 2024

Conversation

jmcarcell
Copy link
Contributor

@jmcarcell jmcarcell commented Apr 23, 2024

BEGINRELEASENOTES

  • Set only one handler for logging in k4run, preventing duplication of logging messages

ENDRELEASENOTES

I'm not sure how since I can't reproduce on main (well I only tried one or two steering files), but on #173 when running with k4run, sometimes the logging messages will be duplicated:

$ k4run ExampleFunctionalMemory.py

[k4run]
# Option name: Transformer.OutputLevel Transformer.OutputLevel 0
[k4run] Option name: Transformer.OutputLevel Transformer.OutputLevel 0
# Option name: Transformer.InputCollection Transformer.InputCollection ['MCParticles']
[k4run] Option name: Transformer.InputCollection Transformer.InputCollection ['MCParticles']
# Option name: Transformer.OutputCollection Transformer.OutputCollection ['NewMCParticles']
[k4run] Option name: Transformer.OutputCollection Transformer.OutputCollection ['NewMCParticles']
# Option name: Transformer.Offset Transformer.Offset 10
[k4run] Option name: Transformer.Offset Transformer.Offset 10
ApplicationMgr    SUCCESS

and this seems to be because there is the default handler and the new one that adds the [k4run] added. This PR sets the list to only be the one that adds [k4run].

One could think this is because of #173 but k4run there is the same as in main so nothing should change with respect to logging. Related: https://stackoverflow.com/questions/6729268/log-messages-appearing-twice-with-python-logging

@andresailer
Copy link
Contributor

could it be caused by a change in #173 in the module imports, where one of the imports creates a handler? Or something directly calling logging.[info|error|warning...] which would call basicConfig if no handler exists?

@jmcarcell
Copy link
Contributor Author

jmcarcell commented Apr 23, 2024

I tried reducing a steering file to the minimum: in the example I quote ExampleFunctionalMemory only loads ExampleFunctionalTransformer from Configurables and INFO and still happens (that means, without apparently importing any of the new python code). So it doesn't seem to be that. Then I checked there isn't any other code calling or importing logging and with pdb I checked addHandler in k4run is being called only once. So I still don't know where it comes from. In any case, this approach should be correct because right now have a single handler so it makes sure there is only one handler.

@jmcarcell
Copy link
Contributor Author

I don't see any downsides to this; I don't know why that was happening but with the fix it should always be correct.

@jmcarcell jmcarcell merged commit 6c55ebd into main Apr 25, 2024
8 of 11 checks passed
@jmcarcell jmcarcell deleted the handlers branch April 25, 2024 17:13
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.

2 participants