First try at changing the logging facilities #544
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ages ago I proposed to migrate to the built in logging facilities to allow for more flexible logging (see #315). Recently I have been using
pyemuagain and faced the same issue I faced then so here is a PR (work in progress) to add logging instead of writing files directly.I decided to first tackle the new
run_spmethod as this was the newest so least likely to break peoples workflows should it be not as stable as I think it is (see #539 / #532).What I have done is create a little method that returns alogging.Loggerobject given the boolean flagsverboseandlogger(which currently is calledlogfilein other methods). However,loggercan also accept alogging.Loggerobject directly. So if you run something like the following code, all messages are recorded inmy_custom.loginstead ofpyemu.log:I have added two helpers, one is
pyemu.log_utils.get_loggerthat returns alogging.Loggerobject that writes topyemu.logor stdout when requested. The second ispyemu.log_utils.set_loggerthat either takes alogging.Logger(as a positional only argument) or keyword arguments that are passed directly tologging.basicConfig:Of course you can go all out in how complicated you want your logging facilities to be, see https://docs.python.org/3/library/logging.html# for all possibilities.