<?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>Pieces of Mind</title>
	<atom:link href="http://pieces.openpolitics.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pieces.openpolitics.com</link>
	<description>Puzzlings on software development and other topics of interest</description>
	<lastBuildDate>Thu, 17 May 2012 00:34:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Low-cost scalable ACID compliant transactions</title>
		<link>http://pieces.openpolitics.com/2012/05/low-cost-scalable-acid-compliant-transactions/</link>
		<comments>http://pieces.openpolitics.com/2012/05/low-cost-scalable-acid-compliant-transactions/#comments</comments>
		<pubDate>Thu, 17 May 2012 00:34:24 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Link]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/?p=294</guid>
		<description><![CDATA[Yale researchers have published a paper and blog entry about a system they have developed that they claim can match Oracle and DB2 at TPC-C performance on commodity hardware and open-source software.]]></description>
			<content:encoded><![CDATA[<p>Yale researchers have published a paper and <a href="http://dbmsmusings.blogspot.com/2012/05/if-all-these-new-dbms-technologies-are.html">blog entry</a> about a system they have developed that they claim can match Oracle and DB2 at TPC-C performance on commodity hardware and open-source software.</p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/05/low-cost-scalable-acid-compliant-transactions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It is pompous to think that, w&#8230;</title>
		<link>http://pieces.openpolitics.com/2012/05/it-is-pompous-to-think-that-w/</link>
		<comments>http://pieces.openpolitics.com/2012/05/it-is-pompous-to-think-that-w/#comments</comments>
		<pubDate>Thu, 03 May 2012 03:43:23 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Tweet]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/2012/05/it-is-pompous-to-think-that-w/</guid>
		<description><![CDATA[It is pompous to think that, with science, we can know all the answers. http://t.co/KI0FqqgP]]></description>
			<content:encoded><![CDATA[<p>It is pompous to think that, with science, we can know all the answers.<br />
<a href="http://t.co/KI0FqqgP" rel="nofollow">http://t.co/KI0FqqgP</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/05/it-is-pompous-to-think-that-w/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>We can’t get enough of one a&#8230;</title>
		<link>http://pieces.openpolitics.com/2012/04/we-cant-get-enough-of-one-a/</link>
		<comments>http://pieces.openpolitics.com/2012/04/we-cant-get-enough-of-one-a/#comments</comments>
		<pubDate>Tue, 01 May 2012 02:50:28 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Tweet]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/2012/04/we-cant-get-enough-of-one-a/</guid>
		<description><![CDATA[We can’t get enough of one another if we can use technology to keep one another at distances we can control http://t.co/laoON27I]]></description>
			<content:encoded><![CDATA[<p>We can’t get enough of one another if we can use technology to keep one another at distances we can control <a href="http://t.co/laoON27I" rel="nofollow">http://t.co/laoON27I</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/04/we-cant-get-enough-of-one-a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heck yeah! What she said. I NE&#8230;</title>
		<link>http://pieces.openpolitics.com/2012/04/heck-yeah-what-she-said-i-ne/</link>
		<comments>http://pieces.openpolitics.com/2012/04/heck-yeah-what-she-said-i-ne/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 14:40:34 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Tweet]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/2012/04/heck-yeah-what-she-said-i-ne/</guid>
		<description><![CDATA[Heck yeah! What she said. I NEVER want a boob job to be compulsory for my daughter. http://t.co/EFEZgheT]]></description>
			<content:encoded><![CDATA[<p>Heck yeah! What she said. I NEVER want a boob job to be compulsory for my daughter. <a href="http://t.co/EFEZgheT" rel="nofollow">http://t.co/EFEZgheT</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/04/heck-yeah-what-she-said-i-ne/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Link: A Brief History of the Corporation: 1600 to 2100</title>
		<link>http://pieces.openpolitics.com/2012/04/link-a-brief-history-of-the-corporation-1600-to-2100/</link>
		<comments>http://pieces.openpolitics.com/2012/04/link-a-brief-history-of-the-corporation-1600-to-2100/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 01:19:40 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Link]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/?p=285</guid>
		<description><![CDATA[http://www.ribbonfarm.com/2011/06/08/a-brief-history-of-the-corporation-1600-to-2100/ Finally got around to finishing this rather long but very intriguing article on the history of the corporation. The points near the end on time are excellent. Must remember this.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ribbonfarm.com/2011/06/08/a-brief-history-of-the-corporation-1600-to-2100/">http://www.ribbonfarm.com/2011/06/08/a-brief-history-of-the-corporation-1600-to-2100/</a></p>
<p>Finally got around to finishing this rather long but very intriguing article on the history of the corporation. The points near the end on time are excellent. Must remember this.</p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/04/link-a-brief-history-of-the-corporation-1600-to-2100/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Logging Best Practices</title>
		<link>http://pieces.openpolitics.com/2012/04/python-logging-best-practices/</link>
		<comments>http://pieces.openpolitics.com/2012/04/python-logging-best-practices/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 05:26:29 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/?p=266</guid>
		<description><![CDATA[Python has wonderful logging package. It is possibly one of the most useful yet widely misused and misunderstood packages in the Python standard library. I learned to use the logging package by reading the documentation and writing applications that use logging. Along the way I have encountered some libraries and frameworks that, shall we say, [...]]]></description>
			<content:encoded><![CDATA[<p>Python has wonderful logging package. It is possibly one of the most useful yet widely misused and misunderstood packages in the Python standard library. I learned to use the logging package by reading the documentation and writing applications that use logging. Along the way I have encountered some libraries and frameworks that, shall we say, use the logging package in ways that are less than helpful to a developer who may wish to incorporate those libraries into his own program. This is a shame. However, I&#8217;m happy to report that all of the inconvenience can be avoided and corrected with a few tips on how to use the various pieces of the logging package in ways that will benefit rather than frustrate those who use code that you write.<span id="more-266"></span></p>
<p>The first important thing to realize about the logging package is that there are four types of objects that each play an important role in getting the logging system working:</p>
<ul>
<li>Loggers – used by application code to send messages to the logging system.</li>
<li>Formatters – format the message for output.</li>
<li>Filters – provide fine-grained output control.</li>
<li>Handlers – send formatted output to a destination such as a file.</li>
</ul>
<p>Of these four types, filters are probably the least important to understand, at least initially. I have rarely used filters. On the other hand, they can help to accomplish things that are hard if not impossible to do without them. For example, in multi-threading network-oriented code, they can be a useful way of getting contextual information into the log (e.g. remote IP address or username, or database-connection-specific info). Also, see this post on <a href="http://plumberjack.blogspot.co.uk/2010/09/configuring-logging-for-web.html">how to configure logging for Web applications</a> – filters are used as part of the solution.</p>
<p>The thing that probably causes most frustration is knowing how, when, and where to use each of these types in an application, framework, or library. Any complete, stand-alone application must use at least three of the four to get proper logging output. The <a href="http://docs.python.org/howto/logging.html">standard library documentation</a> is fairly clear on how to do this. It may be as simple as calling <code>logging.basicConfig</code> or as involved as reading configuration from a YAML file, merging in sensible defaults, and feeding the result to <code>logging.config.dictConfig</code>.</p>
<p><strong>Most of the time library and framework authors should only use Logger objects.</strong> Get a logger and use it to publish log events. That is all. Do not set the logging level. Do not setup formatters or handlers. Otherwise go directly to jail; do not pass Go, do not collect $200. Oh, and fix your logging code while you&#8217;re sitting in jail.</p>
<p>One of the best ways to get a logger is like this:</p>
<pre>log = logging.getLogger(__name__)</pre>
<p>This gets a logger with a name that indicates exactly which module a given logging event originated from (assuming this logger is only used in the module in which it is defined). In general, all modules that need to log should have a module-level logger instantiated with <code>__name__</code>, and code in that module uses that logger. You can also have child loggers of that module logger if you need more fine-grained control. However, since loggers are singletons there is no need to hold a reference to a logger in a class instance. Loggers are singletons for a good reason: it must be possible to reference each logger in order to globally configure and control it. This would not be possible if loggers were not singletons.</p>
<p>Earlier I implied that an application is a stand-alone program. I will take a moment to distinguish between libraries and frameworks for the purposes of this article. A library is something like <a href="http://beaker.readthedocs.org/">Beaker</a>, which provides a particular set of functionality such as a caching system. A framework is something like <a href="https://www.djangoproject.com/">Django</a>—a collection of libraries and glue code that work together to make it easier to write an application. It is imperative that libraries and frameworks use the logging package properly when they choose to use it. Improper use can make a library or framework difficult, not to mention intensely frustrating, to incorporate into a larger application.</p>
<p>With one exception, libraries have no business configuring logging levels, formatters, or handlers. If you are a library author and are tempted to do one or more of those as a convenience for your users, just don&#8217;t do it. You will likely frustrate them more than you help them. As for that one exception, modules that wish to use logging, but do not wish to emit a warning if the library user has not configured logging will want to add a <code>NullHandler</code> to the logger at the top-level of the logging namespace used by the library:</p>
<pre>import logging
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())</pre>
<p>This configures a do-nothing handler that prevents the “No handlers could be found for &#8230;” warning when your library triggers logging events in contexts where handlers have not been otherwise configured. See the <a href="http://docs.python.org/howto/logging.html#configuring-logging-for-a-library">Logging HOWTO</a> for more on this subject.</p>
<p>Note that it is acceptable for libraries to include APIs that configure all the various parts of the logging system, including logging levels, formatters, handlers, and filters. A key point here is that <strong>any such API should be well documented and possible to avoid</strong>. With the noted exception above, this rule expressly prohibits any import-time configuration. This allows the developer to roll her own logging configuration if the provided API does not result in a satisfactory configuration.</p>
<p>As with libraries, it is equally important to follow sound practices when using logging in a framework. A framework may include a bootstrap system, or means with which to get an application running. This often includes some configuration mechanism through which various features are enabled or configured. Logging levels, filters, formats, and handlers are among the things that a framework may want to configure. If your framework must setup a specific handler and/or formatter, do it in a way that can be easily disabled, and <strong>clearly document how to disable it</strong>. By “disable it” I mean disable every single code branch where a filter, handler, or formatter is instantiated or a logging level is set (with <code>setLevel</code>) or a handler is added to a logger (with <code>addHandler</code>). You may want to setup a specific set of handlers and formatters, for example, because you anticipate that most of your users will want a very specific type of logging output. One example of this would be a web framework like <a href="http://cherrypy.org/">CherryPy</a>, which uses the logging system to generate standard access and error logs similar to those generated by Apache. This can be nice when getting a simple web application up and running. However, in more advanced use cases it can be very frustrating if there is no easy way (i.e., other than monkey-patching) to override or disable logging configurations done within a framework.</p>
<p>Logging for an application is most often configured once at startup (although more elaborate scenarios are possible and can be quite useful). This configuration process can be annoyingly hampered by a framework or library doing its own logging configuration in addition to the configuration done by the application developer. In some cases the first configuration wins (e.g., <code>logging.basicConfig</code>), in others you&#8217;ll end up with two competing configurations (e.g., two handlers sending output to the same file resulting in duplicate messages), and in yet other situations the last one wins (e.g., setting the logging level of a given logger or handler). In cases where logging is configured at import-time (generally something to avoid), the order in which modules are imported can change logging behavior in strange and non-intuitive ways. All this is to say that the behavior of the logging package can be very confusing when used improperly. This is compounded when frameworks and libraries configure logging when they should not, and it is often hard to track down such misconfiguration.</p>
<p>As a developer of a framework or library you should always allow or provide a single point of configuration for logging levels, filters, formats, and handlers. When developing a library, just get a logger and log stuff—don&#8217;t mess with any other parts of the logging system. When developing a framework, provide a way to override or disable anything that can be configured by <code>logging.config.dictConfig</code>. Following these simple rules will make your library or framework vastly more convenient for anyone trying to setup advanced logging configurations.</p>
<p>Special thanks to Vinay Sajip for reviewing this article and providing valuable comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/04/python-logging-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>needs to write a post on loggi&#8230;</title>
		<link>http://pieces.openpolitics.com/2012/04/needs-to-write-a-post-on-loggi/</link>
		<comments>http://pieces.openpolitics.com/2012/04/needs-to-write-a-post-on-loggi/#comments</comments>
		<pubDate>Sat, 14 Apr 2012 03:47:03 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Tweet]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/2012/04/needs-to-write-a-post-on-loggi/</guid>
		<description><![CDATA[needs to write a post on logging best practices. Hint: CherryPy is doing it wrong. Was reminded by this: http://t.co/6xMarLak]]></description>
			<content:encoded><![CDATA[<p>needs to write a post on logging best practices. Hint: CherryPy is doing it wrong. Was reminded by this:<br />
<a href="http://t.co/6xMarLak" rel="nofollow">http://t.co/6xMarLak</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/04/needs-to-write-a-post-on-loggi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Glad I never tried anything se&#8230;</title>
		<link>http://pieces.openpolitics.com/2012/04/glad-i-never-tried-anything-se/</link>
		<comments>http://pieces.openpolitics.com/2012/04/glad-i-never-tried-anything-se/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 00:35:08 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Tweet]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/2012/04/glad-i-never-tried-anything-se/</guid>
		<description><![CDATA[Glad I never tried anything serious with PHP http://t.co/FCFvMRtU]]></description>
			<content:encoded><![CDATA[<p>Glad I never tried anything serious with PHP <a href="http://t.co/FCFvMRtU" rel="nofollow">http://t.co/FCFvMRtU</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/04/glad-i-never-tried-anything-se/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;d rather hack than get waste&#8230;</title>
		<link>http://pieces.openpolitics.com/2012/04/id-rather-hack-than-get-waste/</link>
		<comments>http://pieces.openpolitics.com/2012/04/id-rather-hack-than-get-waste/#comments</comments>
		<pubDate>Sat, 07 Apr 2012 14:29:06 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Tweet]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/2012/04/id-rather-hack-than-get-waste/</guid>
		<description><![CDATA[I&#8217;d rather hack than get wasted. @rfunduk http://t.co/h3mzocrT]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d rather hack than get wasted. @<a href="http://twitter.com/rfunduk" class="aktt_username">rfunduk</a>  <a href="http://t.co/h3mzocrT" rel="nofollow">http://t.co/h3mzocrT</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/04/id-rather-hack-than-get-waste/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>global state is magic. magic i&#8230;</title>
		<link>http://pieces.openpolitics.com/2012/04/global-state-is-magic-magic-i/</link>
		<comments>http://pieces.openpolitics.com/2012/04/global-state-is-magic-magic-i/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 16:09:06 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Tweet]]></category>

		<guid isPermaLink="false">http://pieces.openpolitics.com/2012/04/global-state-is-magic-magic-i/</guid>
		<description><![CDATA[global state is magic. magic is hard to understand. don&#8217;t do that #RQ http://t.co/KhsxLOJs]]></description>
			<content:encoded><![CDATA[<p>global state is magic. magic is hard to understand. don&#8217;t do that #<a href="http://search.twitter.com/search?q=%23RQ" class="aktt_hashtag">RQ</a> <a href="http://t.co/KhsxLOJs" rel="nofollow">http://t.co/KhsxLOJs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pieces.openpolitics.com/2012/04/global-state-is-magic-magic-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

