<?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>Kernel Panic &#187; syslog</title>
	<atom:link href="http://blog.epelaez.net/tag/syslog/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.epelaez.net</link>
	<description>~Keep It Simple</description>
	<lastBuildDate>Wed, 30 Jun 2010 17:11:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Improved Logging</title>
		<link>http://blog.epelaez.net/10/improved-logging/</link>
		<comments>http://blog.epelaez.net/10/improved-logging/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 05:58:08 +0000</pubDate>
		<dc:creator>Pelaez</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[NSLog]]></category>
		<category><![CDATA[syslog]]></category>

		<guid isPermaLink="false">http://blog.epelaez.net/?p=609</guid>
		<description><![CDATA[This is an improved logging technique I developed in the last couple of days. It&#8217;s not to debug an specific problem, but to get a general idea of where your bug is, and if there are no bugs, to know the stack of methods called. It&#8217;s quite simple, but it does require some work to [...]]]></description>
			<content:encoded><![CDATA[<p>This is an improved logging technique I developed in the last couple of days. It&#8217;s not to debug an specific problem, but to get a general idea of where your bug is, and if there are no bugs, to know the stack of methods called.</p>
<p>It&#8217;s quite simple, but it does require some work to implement. If you have a big project, it could take some time to implement.</p>
<p><span id="more-609"></span></p>
<h3><strong>Instructions</strong>:</h3>
<p>First, get <a href="http://github.com/Pelaez/Kernel-Panic-Classes/tree/master/Classes/KPLogHelper/" target="_blank">this class</a>, and add it to your project.</p>
<p>Then, in your prefix file, add the following lines:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#import &quot;KPLogHelper.h&quot;</span><br />
<span style="color: #6e371a;">#define  LOG_IN NSLog(@&quot;XX:%@ %s&quot;,[KPLogHelper indent:1], __PRETTY_FUNCTION__);</span><br />
<span style="color: #6e371a;">#define LOG_OUT NSLog(@&quot;XX:%@ %s&quot;,[KPLogHelper indent:-1], __PRETTY_FUNCTION__);</span><br />
<span style="color: #6e371a;">#define  LOG_NO NSLog(@&quot;XX:%@ %s&quot;,[KPLogHelper indent:0], __PRETTY_FUNCTION__);</span><br />
<span style="color: #6e371a;">#define &nbsp;LOG(x) NSLog(@&quot;iPC:%@ %@&quot;, [KPLogHelper indent:0], x);</span></div></td></tr></tbody></table></div>
<p>The XX should be two characters to filter your logs, it&#8217;s not necesary, but it&#8217;s useful. You can find more about that <a href="http://blog.epelaez.net/08/nslog-and-syslog/">here</a>.</p>
<p>And finally, at the beginning of every method you want to log, add <code class="codecolorer objc twitlight"><span class="objc">LOG_IN</span></code>, at the end of the method, and before any returns, add <code class="codecolorer objc twitlight"><span class="objc">LOG_OUT</span></code>.</p>
<p>If it&#8217;s a really small method and you don&#8217;t want to know where it starts and when it ends, but only when it happened, just add <code class="codecolorer objc twitlight"><span class="objc">LOG_NO</span></code>.</p>
<p>If you want to log with a custom string while respecting the indent level <code class="codecolorer objc twitlight"><span class="objc">LOG<span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>here<span style="color: #002200;">&#41;</span></span></code>.</p>
<p>The result in the log will be a message when the method is called with an indent level, and the methods that are called before it ends will have an indentation level greater by one, then the indentation level will be reduced by one when the method ends.</p>
<p>It will look something like:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&gt;&gt;&gt; Method 1 signature //When the first method begins: LOG_IN<br />
&gt;&gt;&gt;&gt;&gt;&gt; Method 2 signature //When the second method is called by the 1st: LOG_ING<br />
====== Method 3 signature //When the 3rd method is called by 2nd: LOG_NO<br />
&lt;&lt;&lt;&lt;&lt;&lt; Method 2 Signature //When the second method returns: LOG_OUT<br />
&lt;&lt;&lt; Method 2 signature //When the first method returns: LOG_OUT</div></td></tr></tbody></table></div>
<p>To stop showing the log, just comment the methods so it looks like this:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6e371a;">#define &nbsp;LOG_IN //NSLog(@&quot;XX:%@ %s&quot;,[KPLogHelper indent:1], __PRETTY_FUNCTION__);</span></div></td></tr></tbody></table></div>
<p>NOTE: Make sure you disable this logging before releasing you app, as it&#8217;s a little heavier than the standard logging (due to the calculations to make the indent) and will slow down your app.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://blog.epelaez.net/10/improved-logging/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.epelaez.net/10/improved-logging/&amp;title=Improved+Logging" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.epelaez.net/10/improved-logging/&amp;title=Improved+Logging" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.epelaez.net/10/improved-logging/&amp;t=Improved+Logging" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22Improved%20Logging%22&amp;body=Link: http://blog.epelaez.net/10/improved-logging/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A This%20is%20an%20improved%20logging%20technique%20I%20developed%20in%20the%20last%20couple%20of%20days.%20It%27s%20not%20to%20debug%20an%20specific%20problem%2C%20but%20to%20get%20a%20general%20idea%20of%20where%20your%20bug%20is%2C%20and%20if%20there%20are%20no%20bugs%2C%20to%20know%20the%20stack%20of%20methods%20called.%0D%0A%0D%0AIt%27s%20quite%20simple%2C%20but%20it%20does%20require%20some%20work%20to%20implement.%20If%20you" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Improved+Logging+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.epelaez.net/10/improved-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSLog and Syslog</title>
		<link>http://blog.epelaez.net/08/nslog-and-syslog/</link>
		<comments>http://blog.epelaez.net/08/nslog-and-syslog/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 23:50:25 +0000</pubDate>
		<dc:creator>Pelaez</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[NSLog]]></category>
		<category><![CDATA[saurik]]></category>
		<category><![CDATA[syslog]]></category>

		<guid isPermaLink="false">http://blog.epelaez.net/?p=332</guid>
		<description><![CDATA[To help you debugging, there&#8217;s the NSLog method, and Syslog, on Cydia, by saurik, enables logging in the iDevice. To use it, simply put: NSLog&#40;@&#34;A string here&#34;&#41;; Then, when executed, it will write that to a file on the iDevice, on /var/log/syslog. To see the log, you can open the file on a text editor, [...]]]></description>
			<content:encoded><![CDATA[<p>To help you debugging, there&#8217;s the NSLog method, and Syslog, on Cydia, by saurik, enables logging in the iDevice.</p>
<p>To use it, simply put:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;A string here&quot;</span><span style="color: #002200;">&#41;</span>;</div></div>
<p><span id="more-332"></span></p>
<p>Then, when executed, it will write that to a file on the iDevice, on /var/log/syslog.</p>
<p>To see the log, you can open the file on a text editor, or simply use:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ cat /var/log/syslog</div></div>
<p>To make it easier to find the logs that matter to you (because keep in mind that it will log whatever the Springboard and other apps want to log), what I do is to add some letters at the beginning of the string.<br />
Imagine we are making an app called &#8220;Kernel Panic App&#8221;, so when you log something, you would do it like this:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;KPA: Successfully saved the file&quot;</span><span style="color: #002200;">&#41;</span>;</div></div>
<p>Then, to see only tags by that app, we would do this on the terminal:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ cat /var/log/syslog | grep KPA</div></div>
<p>That will output only the lines that have our tag on it. A couple of lines that don&#8217;t matter to us (depending on what tag we are using) might slip, but certainly, they will be a lot less.</p>
<p>If you want to save that output into a file, you can do this on the terminal:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ cat /var/log/syslog | grep KPA &gt;&gt; MyLog1</div></div>
<p>Also, for a better log, you can put variables in the string. It&#8217;s a string format, so it accepts things like:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:400px;"><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Objects: %i, User: %@&quot;</span>, anInt, anNSString<span style="color: #002200;">&#41;</span></div></div>
<p>That way, you can produce a better log, by outputting numbers and strings that might be useful to know what is your app doing.</p>
<p>Hope you can find a good use for this!</p>
<p>Please send me an e-mail if I got anything wrong, so I can fix it.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://blog.epelaez.net/08/nslog-and-syslog/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.epelaez.net/08/nslog-and-syslog/&amp;title=NSLog+and+Syslog" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.epelaez.net/08/nslog-and-syslog/&amp;title=NSLog+and+Syslog" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://blog.epelaez.net/08/nslog-and-syslog/&amp;t=NSLog+and+Syslog" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22NSLog%20and%20Syslog%22&amp;body=Link: http://blog.epelaez.net/08/nslog-and-syslog/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A To%20help%20you%20debugging%2C%20there%27s%20the%20NSLog%20method%2C%20and%20Syslog%2C%20on%20Cydia%2C%20by%20saurik%2C%20enables%20logging%20in%20the%20iDevice.%0D%0A%0D%0ATo%20use%20it%2C%20simply%20put%3A%0D%0A%5Bcc%20lang%3D%27objc%27%20line_numbers%3D%22false%22%5DNSLog%28%40%22A%20string%20here%22%29%3B%5B%2Fcc%5D%0D%0A%0D%0A%0D%0A%0D%0AThen%2C%20when%20executed%2C%20it%20will%20write%20that%20to%20a%20file%20on%20the%20iDevice%2C%20on%20%2Fvar%2Flog%2Fsyslog." rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=NSLog+and+Syslog+-+&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://blog.epelaez.net/08/nslog-and-syslog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
