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&rsquo;s happening, it&rsquo;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,&nbsp;which&nbsp;is&nbsp;of&nbsp;itself&nbsp;a&nbsp;great&nbsp;tool,&nbsp;however&nbsp;it&nbsp;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&rsquo;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=&#39;loggingFile.log&#39;, level=logging.DEBUG, format=&#39;%(asctime)s:%(levelname)s:%(message)s&#39;) </pre> <p>A full list of the options available can be gotten at the logrecord attributes&nbsp;<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>