Should I use the print function or logging module??
<p>Logging is the process of outputting messages from your code/script either to the terminal or mostly to a file, in order to be informed on what’s happening, it’s a great use in debugging and can be used in other situations to.</p>
<p>Quite a lot of programmers use the print function, which is of itself a great tool, however it becomes extremely strenous during large projects, also logging is useful when checking the status of a program, for this reason and more logging is recommended.</p>
<p><strong>How to get started</strong><br />
In python, the logging module is preinstalled just have to import it.</p>
<p>It’s as simple as just...</p>
<pre>
import logging
</pre>
<p>We can then setup some little configurations of our choice. By default logging logs to the terminal, We can setup a dedicated file for logging, give a specific level of logging we want to use, and also a format output for the logging.</p>
<pre>
logging.basicConfig(filename='loggingFile.log', level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(message)s')
</pre>
<p>A full list of the options available can be gotten at the logrecord attributes <a href="https://docs.python.org/3/library/logging.html#logrecord-attributes" rel="noopener ugc nofollow" target="_blank">here</a>.<br />
In order to prevent logging clashes from different modules when we import them, we can set different loggers for each module.</p>
<p><a href="https://medium.com/@phurhardeen/should-i-use-the-print-function-or-logging-module-17d35ff8ab94">Read More</a></p>