Python – Logging in Python

Logging in Python is beautifully implemented with the logging library –

It simply does anything you need and you do not need to write something yourself, like I did some time ago here in my VBA Boilerplate.

A nice forest path, with no log once you walk through it.

So, if you are coming from the VBA world (which you are probably not, but you are browsing this site, so you never know…), you will be amazed how neat the logging is done in python. The “beauty” below makes a logging file and adds data to it, whenever it is accessed:

Yup. The logging is beautiful:

Quite what we expected. And speaking of beautiful, take a look at the black formatter here – It is quite nice and to run it you only need these lines:

python3 -m black – works for the explicitly mentioned python file.

python3 -m black . – works for each python file in the whole directory.

That’s all!

Tagged with: , , ,