Do you log a lot like me in your
You can see that both have the same log content but it's hard to follow
The formatter is as below:
Now the output will something like below:
You can see that log content is so much easier to follow by using space padding. It may not be obvious on telegram with small devices. So try it your self :)))
#python #logging #log #logger #formatter #log_formatter #space_padding #padding
Python
modules? If so, you had the same problem to always find the first occurence of a log after time, filename, etc. Let's clarify this with a sample log:[2012-10-02 application.py:1 _get()] DEBUG: this is a log content
[2012-10-02 db.py:1005 _fetch_all_info()] INFO: this is a log content
You can see that both have the same log content but it's hard to follow
cause of length of file name, line number and function name. To format this better we can have space padding in formatters. spaces are identified by `s
. Now lets see the same log, but this time with space padding.The formatter is as below:
[%(asctime)s %(filename)15s:%(lineno)4s %(funcName)20s()] %(levelname)s %(message)s
NOTE: this is not the exact formatter for the above log, it is for demonstration!
Now the output will something like below:
[2012-10-02 application.py: 1 _get()] DEBUG: this is a log content
[2012-10-02 db.py: 1005 _fetch_all_info()] DEBUG: this is a log content
You can see that log content is so much easier to follow by using space padding. It may not be obvious on telegram with small devices. So try it your self :)))
#python #logging #log #logger #formatter #log_formatter #space_padding #padding