<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>t+1 - Latest Comments in The python logging module is much better than print statements</title><link>http://tplus1.disqus.com/</link><description></description><atom:link href="https://tplus1.disqus.com/the_python_logging_module_is_much_better_than_print_statements/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 24 Feb 2015 05:39:14 -0000</lastBuildDate><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-1872405778</link><description>&lt;p&gt;Thanks a lot meow mix.... great explanation.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Teja Ram Seervi</dc:creator><pubDate>Tue, 24 Feb 2015 05:39:14 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-1494032792</link><description>&lt;p&gt;Thank you for this article. It really helps me with switching to logging !&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Shank</dc:creator><pubDate>Sun, 20 Jul 2014 09:12:21 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-780138010</link><description>&lt;p&gt;Hey, Thanks for the comment!&lt;/p&gt;&lt;p&gt;In my experience, bugs that crash by throwing uncaught exceptions go away over time as a system spends time in production.  After that phase, it becomes more important for a program to leave some kind of audit trail, so you can verify that it is doing what you want it to be doing.&lt;/p&gt;&lt;p&gt;At the same time, if you log every frackin' variable assignment, then you create a needle in the haystack problem.&lt;/p&gt;&lt;p&gt;Two tricks I know of that help here:&lt;/p&gt;&lt;p&gt;1.  I use log levels (DEBUG, INFO, etc) to break up what I log and why.  I log every state-changing operation as INFO.  So, when a user logs in to my web app, that's an INFO.  And when my cron script updates some database rows, that's an INFO too.&lt;/p&gt;&lt;p&gt;Every instance of invalid input data gets logged as an ERROR.  CRITICAL errors are just the things that I can't recover from, like say, a lost database connection.&lt;/p&gt;&lt;p&gt;I use DEBUG logging for the stuff that I may ned later when debugging. Usually though, the less DEBUG logs, the better.  I prefer to log the original state of the program, like maybe the whole HTTP request if I'm doing web programming, and then avoid logging all the various derived values, because I can usually recreate those given that I know the initial inputs.&lt;/p&gt;&lt;p&gt;2.  When you make a logger, like::&lt;/p&gt;&lt;p&gt;import logging&lt;br&gt;log = logging.getLogger('...')&lt;/p&gt;&lt;p&gt;You should use a name that relates to what kind of logging messages you'll put in.  In other words, all my database modelling modules have a logger like this::&lt;/p&gt;&lt;p&gt;log = logging.getLogger('project.model')&lt;/p&gt;&lt;p&gt;But I make logs in cron jobs like this:&lt;/p&gt;&lt;p&gt;log = logging.getLogger('project.cron_job')&lt;/p&gt;&lt;p&gt;If you use different named logs like that, you can configure your logging handlers to put stuff in different places.  So, for example, you could have all your logs from one part of your program in one text file, separate from another part.&lt;/p&gt;&lt;p&gt;Good luck!&lt;/p&gt;&lt;p&gt;Matt&lt;/p&gt;&lt;p&gt;PS: I did a big ol' talk at PyOhio this summer all about logging.  Here's the text from that talk: &lt;a href="https://github.com/mw44118/really-good-logging/blob/master/finished-stuff.txt" rel="nofollow noopener" target="_blank" title="https://github.com/mw44118/really-good-logging/blob/master/finished-stuff.txt"&gt;https://github.com/mw44118/...&lt;/a&gt; &lt;br&gt;There's a lot of "real world" scenarios that I hash through in there.  You can also find the video from the talk on youtube.  Search for PyOhio really good logging.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Matt Wilson</dc:creator><pubDate>Sun, 27 Jan 2013 20:21:32 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-779062806</link><description>&lt;p&gt;Great article, but I'm still a little confused about how I would apply this in a much larger scenario.  I've written a program for a friend's business, and it currently contains thousands of lines of code spanning several modules.  Most bugs that throw exceptions are easily found and fixed by the traceback details, but there have been a few times where I've had to add print statements to help me track down problems that *didn't* throw an exception.  The program is kicked off by a main() function, so would I simply add logging calls to main(), similar to what you've done with f(), or should I go through the entire thing and add more logging calls in specific places?  In other words, how do you determine what level of logging is appropriate for a given situation?  I suppose I could log just about everything that happens with the program, but I'd rather not bloat it with so many logging calls that it becomes a huge mess.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Justin S Barrett</dc:creator><pubDate>Sat, 26 Jan 2013 11:45:45 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-498273419</link><description>&lt;p&gt;sometimes, I catch myself reverting to print statements also. It's sooo easy and if the previous developer used it on their coding... I tend to be consistent (if I'm doing their work for them). I have to hear all the wining when a programmer can't read their own code because I didn't modify it according to their ever changing standards. I might as well go back to developing &lt;a href="http://www.everifyfaq.com" rel="nofollow noopener" target="_blank" title="http://www.everifyfaq.com"&gt;online background checks&lt;/a&gt;.&lt;br&gt; Keep pushing the code, bro... &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Heather</dc:creator><pubDate>Sun, 15 Apr 2012 12:42:04 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-428929084</link><description>&lt;p&gt;Mike Pirnat's slides have been moved to here: &lt;a href="http://mike.pirnat.com/static/joy-of-logging.pdf" rel="nofollow noopener" target="_blank" title="http://mike.pirnat.com/static/joy-of-logging.pdf"&gt;http://mike.pirnat.com/stat...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Fri, 03 Feb 2012 17:03:50 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-379976378</link><description>&lt;p&gt;Good luck!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Matt Wilson</dc:creator><pubDate>Mon, 05 Dec 2011 20:28:43 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-379954960</link><description>&lt;p&gt;Right.  Sold.  I'm going to use Python Logger as well.  Thanks, great article.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Eric</dc:creator><pubDate>Mon, 05 Dec 2011 19:44:39 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-355759474</link><description>&lt;p&gt;grazie!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Matt Wilson</dc:creator><pubDate>Fri, 04 Nov 2011 11:39:21 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-355757053</link><description>&lt;p&gt;great tutorials&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Motore Asincrono</dc:creator><pubDate>Fri, 04 Nov 2011 11:35:58 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-332147610</link><description>&lt;p&gt;Hilarious!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Matt Wilson</dc:creator><pubDate>Tue, 11 Oct 2011 20:46:22 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-332139878</link><description>&lt;p&gt;thanks meow mix, you really helped me through a tough time of trying not to use print statements.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">bahamas10</dc:creator><pubDate>Tue, 11 Oct 2011 20:34:38 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-277567533</link><description>&lt;p&gt;so true... I often find myself asking the same question when using python logger&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">cheeseinvert</dc:creator><pubDate>Thu, 04 Aug 2011 15:12:57 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-170645052</link><description>&lt;p&gt;I agree with meow mix&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Noyes</dc:creator><pubDate>Wed, 23 Mar 2011 21:15:44 -0000</pubDate></item><item><title>Re: The python logging module is much better than print statements</title><link>http://blog.tplus1.com/blog/2007/09/28/the-python-logging-module-is-much-better-than-print-statements/#comment-162423320</link><description>&lt;p&gt;&lt;br&gt;It can be overwhelming and frustrating at times. How do you choose �the one� that works with the �other ones� you will love and care for, and will in return inspire, bring value and joy.&lt;br&gt; ... &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">meow mix coupons</dc:creator><pubDate>Tue, 08 Mar 2011 11:32:25 -0000</pubDate></item></channel></rss>