Photo by Milkovi on Unsplash

Why You Should Use Logzero as a Logger in Your Data Science Projects

Logging is a sort of improvement for python print statements. Let’s see why, and how the great logzero package helps to make easy and nice logs.

Thibaud Lamothe 🤠
The Startup
Published in
5 min readMay 31, 2020

Printing or Logging?

Print is the first statement everyone learns when starting with Python. It is also one of the scarce statement which makes the difference between Python 2 and Python 3. Python-ers have a history of printing.

print(‘Hello World!’)

The print statement is very useful and allows you to track information while your code is running. But it has one huge drawback: when you close your python session or re-run a notebook cell, you lose all the printed information. Even the important ones. And this is even more true when it comes to Machine Learning, where you often need to run grid search or any iterative process:

  • Select parameters / print parameters / run experiment / print accuracy through epochs
  • Observe results / change an hyper-parameter / Re-run experiment / Loose the previous printed informations

To prevent these losses, you could use the logging module which is part of the python standard library. The main advantages of using a logger are the followings :

  • Save all your logs in a separate file. You can analyze them later. (Of course, it still prints the information in your console.)
  • Select a logging level for each logged line: Debug, Info , Warning or Error.
  • It provides the exact hour of occurrence and the line of the log statement.
  • Easy to use. As easy as import logging and logging.warning('This is important but not critical').

Not only does it make bug-tracking much easier and efficient but it also allows you to save information through times without losing any results.

This is why you should use logging instead of printing. The good news is that there is a very powerful python package called logzero which makes python logging even more powerful and efficient.

The power of Logzero

--

--

Thibaud Lamothe 🤠
The Startup

Head of Data @ Iroko, from Paris | Visit my website www.etomal.com | Unlock unlimited content medium.etomal.com/membership | 🤠