As a best practice, we often use logging to record.
We used to use print
to log records:
This is not an efficient way for logging: neither providing sufficient info, nor offering the flexibility to modify. Therefore we considered to use logging
module to tackle this problem.
Both Good logging practice in Python and Logging — The Hitchhiker’s Guide to Python provide comprehensive guides to this topic. However, constructing a simple logger should not be so complicated.
We can just write a three-line logger to cope this task.
In this way we can just this snippet in other functions to log the records. For example:
The output looks like this:
Life is much easier!