<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Death of a Gremmie &#187; logging</title>
	<atom:link href="http://deathofagremmie.com/tag/logging/feed/" rel="self" type="application/rss+xml" />
	<link>http://deathofagremmie.com</link>
	<description>by Brian Neal</description>
	<lastBuildDate>Wed, 14 Jul 2010 02:31:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Django and Python Logging</title>
		<link>http://deathofagremmie.com/2009/06/12/django-and-python-logging/</link>
		<comments>http://deathofagremmie.com/2009/06/12/django-and-python-logging/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 01:23:06 +0000</pubDate>
		<dc:creator>gremmie</dc:creator>
				<category><![CDATA[SG101 2.0]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://deathofagremmie.com/?p=271</guid>
		<description><![CDATA[I started working on a simple Django application for accepting and recording Paypal donations. While I was working on the IPN code, it suddenly occurred to me that I really needed a way to log any errors that might occur. After all the IPN process will be initiated by Paypal completely out of my control [...]]]></description>
			<content:encoded><![CDATA[<p>I started working on a simple Django application for accepting and recording Paypal donations. While I was working on the <a href="https://www.paypal.com/ipn">IPN</a> code, it suddenly occurred to me that I really needed a way to log any errors that might occur. After all the IPN process will be initiated by Paypal completely out of my control (not counting the <a href="https://developer.paypal.com/">Paypal sandbox</a>) and without any visual feedback. Thus, I&#8217;d like a record of the path through my code to make sure everything is working the way I expected.</p>
<p>I had learned about the brilliant <a href="http://docs.python.org/library/logging.html">Python logging module</a> some time ago, and had even used it in my IRC bot application. But could you use this with Django?</p>
<p>I did some research and found a couple of blog posts and related Django projects. After studying them I came to the conclusion that indeed the Python logging module is an excellent way to add logging to your web application. And after working with it again, I am very impressed by the functionality that it offers and how easy it is to use. I would have killed to have something like this in my PHP days. So I laced some logging calls throughout my IPN listener code, and I&#8217;ll know soon enough if it works correctly. I&#8217;ll post more about this later. But for now, I&#8217;d like to add some links to the things I found useful related to logging in Django.</p>
<p>First there is this very useful blog post by <a href="http://simonwillison.net/">Simon Willison</a> titled &#8220;<a href="http://simonwillison.net/2008/May/22/debugging/">Debugging Django</a>.&#8221; In addition to talking about logging, Simon also has tips on using the Python debugger, asserts, and some useful middleware.</p>
<p>Second, there is a Django application called <a href="http://code.google.com/p/django-logging/wiki/Overview">django-logging</a>. This application seems mainly aimed at getting your logging statements displayed at the bottom of your web pages while debugging a problem. Of course you could also hook in a logger to log to a file, which is more of what I wanted to do. Another useful feature of this application is that you can configure it to automatically log your application&#8217;s SQL queries.</p>
<p>And finally I looked at <a href="http://www.fairviewcomputing.com/blog/2008/03/05/django-request-logging/">Fairview Computing&#8217;s Django request logging</a>, or drlog. This project provides some middleware which adds the ability to add a unique identifier to each log entry to associate it with a given HTTP request. This allows you to easily trace a single request, even while multiple concurrent requests are happening.</p>
<p>Studying Simon&#8217;s blog post and the source code for the above two applications was very enlightening. In the end I decided to start with the bare Python logging facility for now, configuring it to write to a file. I was reassured to read that <a href="http://docs.python.org/library/logging.html#thread-safety">the Python logging module is thread safe</a>. If I start using the logging module heavily, I may use the drlog middleware to help me map log statements to HTTP requests.</p>
]]></content:encoded>
			<wfw:commentRss>http://deathofagremmie.com/2009/06/12/django-and-python-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
