<?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>LAMPlights &#187; splunk</title>
	<atom:link href="http://www.hermanradtke.com/blog/tag/splunk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hermanradtke.com</link>
	<description>Personal anecdotes from my experiences using the LAMP stack</description>
	<lastBuildDate>Wed, 25 Jan 2012 18:14:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Logging Exception Traces To syslog</title>
		<link>http://www.hermanradtke.com/blog/logging-exception-traces-to-syslog/</link>
		<comments>http://www.hermanradtke.com/blog/logging-exception-traces-to-syslog/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 18:02:44 +0000</pubDate>
		<dc:creator>Herman Radtke</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[splunk]]></category>
		<category><![CDATA[syslog]]></category>

		<guid isPermaLink="false">http://www.hermanradtke.com/blog/?p=325</guid>
		<description><![CDATA[If you have ever visited StackOverflow.com you may have noticed the ads for Splunk.  Splunk aggregates log files together and provides a web interface to search through those logs.  The setup for php is easy: set the php.ini error_log value to "syslog".  The Splunk instructions show you how add a single line to your syslong.conf [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever visited <a class="zem_slink" title="Stack Overflow" rel="homepage" href="http://stackoverflow.com/">StackOverflow.com</a> you may have noticed the ads for <a class="zem_slink" title="Splunk" rel="homepage" href="http://www.splunk.com/">Splunk</a>.  Splunk aggregates log files together and provides a web interface to search through those logs.  The setup for php is easy: set the php.ini error_log value to "<a class="zem_slink" title="Syslog" rel="wikipedia" href="http://en.wikipedia.org/wiki/Syslog">syslog</a>".  The Splunk instructions show you how add a single line to your syslong.conf to have syslog send those messages over to Splunk.<span id="more-325"></span></p>
<p>The only downside to this is that syslog commonly has a limit of 1024 characters per message.  You can change this, but you have to recompile the kernel.  This is especially frustrating when an uncaught exception gets logged.  The log message looks something like this:</p>
<blockquote><p>PHP Fatal error:  Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY093]:<br />
Invalidparameter number: no parameters were bound' in /some/path/to/Zend/Db/Statement<br />
/Pdo.php:234Stack trace: #0 /some/path/to/Zend/Db/Statement.php(320): Zend_Db_Statement_<br />
Pdo-&gt;_execute(Array)#1 /some/path/to/Zend/Db/Adapter/Pdo/Mysql.php(572): Zend_Db_<br />
Statement-&gt;execute(Array) #2 /some/path/to/Zend/Db</p></blockquote>
<p>If you have used Zend_Db_Statement you have probably seen this error message.  If not, it simply means that too few variables are being specified or one of the variables is null when trying to bind all the variables to the placeholders in a SQL statement.  Do you see the problem with this log message though?  It gets cut off way before the stack trace provides any hint as to what code caused it.  If I am using automated testing, it may be very difficult to tell what actually caused the exception.</p>
<p>To get around this, I wrote an exception handler to split the stack trace into separate messages.</p>
<blockquote><p>SQLSTATE[HY093]: Invalid parameter number: no parameters were bound Strack Trace:<br />
PHP 0. _execute /some/path/to/Zend/Db/Statement.php:320<br />
PHP 1. execute /some/path/to/Zend/Db/Adapter/Pdo/Mysql.php:572<br />
PHP 2. query /some/path/to/Zend/Db/Table/Abstract.php:1509<br />
PHP 3. _fetch /some/path/to/Zend/Db/Table/Abstract.php:1325<br />
PHP 4. getDooDads /some/path/to/application/default/models/DooDads.php:112<br />
PHP 5. getAction /some/path/to/application/default/controllers/DooDadsController.php:15<br />
PHP 6. init /some/path/to/Zend/Controller/Action.php:133<br />
PHP 7. __construct /some/path/to/Zend/Controller/Dispatcher/Standard.php:262<br />
PHP 8. dispatch /some/path/to/Zend/Controller/Front.php:946<br />
PHP 9. dispatch /some/path/to/html/index.php:23</p></blockquote>
<p>Now it is very clear that I need to add some more validation to my DooDads model.</p>
<p>The code is on github <a href="http://github.com/hradtke/crimson/tree/master/Crimson_ExceptionHandler/">here</a>.  I am able to just drop it in to any project I am working on and get more verbose logging via syslog.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/8665acfa-63c5-429c-8dbf-6d77b874e655/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_e.png?x-id=8665acfa-63c5-429c-8dbf-6d77b874e655" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 18px; width: 1px; height: 1px;">PHP Fatal error:  Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY093]:<br />
Invalidparameter number: no parameters were bound' in /some/path/to/Zend/Db/Statement/Pdo.php:234<br />
Stack trace: #0 /some/path/to/Zend/Db/Statement.php(320): Zend_Db_Statement_Pdo-&gt;_execute(Array)<br />
#1 /some/path/to/Zend/Db/Adapter/Pdo/Mysql.php(572): Zend_Db_Statement-&gt;execute(Array) #2 /some/<br />
path/to/Zend/Db</div>
]]></content:encoded>
			<wfw:commentRss>http://www.hermanradtke.com/blog/logging-exception-traces-to-syslog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

