The logging file mode. ‘a’ for append, ‘w’ for overwrite
backupCount
int
5
The number of backup files to keep
maxBytes
int
5242880
The maximum size of the log file in bytes
Returns
Logger
Example usage
We must make sure the logging works when we are testing indivudual notebooks and when running the complete code. To accomplish this we can do the following.
First in run.py or other entry point of the project, add the following to get the logging when the complete code is run:
from hopsa import set_loggingif__name__=="__main__": log_dir ="../logs" set_logging(log_dir=log_dir, level=10)
The #| export nbdev directive makes sure this cell will be used in the python module. The #| eval: false nbdev directive makes sure this cell will run when we run the notebook, but it won’t be used in the Python module and it also won’t be tested when we run nbdev_prepare.
INFO - Log file: /home/jelle/code/hopsa/logs/hopsa.log
INFO - Log file: /home/jelle/code/hopsa/logs/hopsa.log
INFO - Log file mode: a
INFO - Log file mode: a
INFO - Log backup count: 5
INFO - Log backup count: 5
INFO - Log max bytes: 5242880
INFO - Log max bytes: 5242880
for h in rt_logger.handlers: h.close() rt_logger.removeHandler(h)print(f"Removed handler: {h}")