Open arushanova opened 9 years ago
Logging in python seems to be pretty straightforward, it just involves import
ing the logging
module everywhere you wish to save messages to the log file. There tutorial is quite easy to follow. It has logging options similar to RAT, so you can log, info
, warning
and debug
level information.
@arushanova did you want to start having a look at adding in basic logging?
@ashleyrback I think all of us should do that and if possible include this in the new codes as well as update old methods. This would help a lot even for debugging.
Update on this: the latest PR (#114) adds the logging infrastructure through utilities.start_logging
and adds some relevant logging information to most modules. @arushanova are you happy with this form of logging, how the output looks etc.
I'll add a quick tutorial in a comment below.
I'll keep the issue open a bit longer until almost all modules are covered and as a reminder for new module we add.
To create a log file, place:
logger = utilities.start_logging()
at the start of your script. It has a couple of options for the log-file naming convention.
You can then add messages to the log-file from your script:
logger.warning("This is a warning") # printed in yellow to terminal
logger.info("This is information") # printed to terminal
logger.debug("This is debug information") # not printed to terminal
The logging information from other modules will also be printed to the terminal and log-file. The logger in each script/module has the same name as the script/module, which is printed before the log message, so you know where it comes from.
I completely support the idea to keep the output as clean as possible. At the same time I've noticed that sometimes the code is supposed to stop (i.e. continue statement) and there are no comments before, explaining what caused this stop. Additionally if we use more than one method, but combination it might be useful to track what steps have been performed and other details.
Ashley and I discussed this and Ashley has suggested making a log file. In this case we will do both - keep the output clean and have all necessary information saved.
P.S. I suppose having log file helps in fitting and limit setting. Usually there's too many lines to output to the screen.