<?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>mikhail panchenko / blog &#187; logging</title>
	<atom:link href="http://mihasya.com/blog/tag/logging/feed/" rel="self" type="application/rss+xml" />
	<link>http://mihasya.com/blog</link>
	<description>good things now come in packages of three</description>
	<lastBuildDate>Sat, 14 Jan 2012 07:28:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Reusable Logging in Django Apps</title>
		<link>http://mihasya.com/blog/reusable-logging-in-django-apps/</link>
		<comments>http://mihasya.com/blog/reusable-logging-in-django-apps/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 21:21:45 +0000</pubDate>
		<dc:creator>mihasya</dc:creator>
				<category><![CDATA[dev]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://mihasya.com/blog/?p=237</guid>
		<description><![CDATA[I have 3 drafts sitting in my queue &#8211; 1 really long post and 2 short ones. I&#8217;ve been picking away at the long post on the shuttle rides, but in the meantime I&#8217;m gonna try to push out the two quick ones. This is one of the quick ones. I was trying to figure [...]]]></description>
			<content:encoded><![CDATA[<p>I have 3 drafts sitting in my queue &#8211; 1 really long post and 2 short ones. I&#8217;ve been picking away at the long post on the shuttle rides, but in the meantime I&#8217;m gonna try to push out the two quick ones. This is one of the quick ones.</p>

<p>I was trying to figure out how to set up reusable logging in my apps and have it fairly decoupled from the overall project. Here&#8217;s what I came up with:</p>

<ol>
    <li>Set up a logger object using <a title="Python logging module" href="http://docs.python.org/library/logging.html" target="_blank">these</a> instructions in settings.py and store it in the LOGGER variable.</li>
    <li>Grab it inside apps using django.conf.settings like so:</li>
</ol>

<p><pre>from django.conf import settings
try:
    logging = settings.LOGGER
except AttributeError:
    import logging</pre>
Then just use logging.debug, logging.info etc. Thus, if a LOGGER is configured inside the project&#8217;s settings.py, we use that (django.conf.settings points to the settings.py for whatever project you&#8217;re working inside of, so you can move your app project to project no problem). Otherwise, we just use vanilla logging functions with the global logging configuration. Nice and sweet.</p>

<p>Suggestions on other ways to do this are, as always, welcome.</p>

<p>Example on django snippets: <a title="Reusable Logging on Django Snippets" href="http://www.djangosnippets.org/snippets/1345/" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://mihasya.com/blog/reusable-logging-in-django-apps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

