<?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>logging | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/logging/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Mon, 23 Mar 2020 20:09:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>logging | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Using rsyslog to log</title>
		<link>https://learncgames.com/using-rsyslog-to-log/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-rsyslog-to-log</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 29 Mar 2020 23:00:49 +0000</pubDate>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[syslog]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=260</guid>

					<description><![CDATA[<p>I&#8217;m a great fan of logging; it helps you find out what&#8217;s happening in a program even if you can&#8217;t debug it. Linux, well Ubuntu has a service (sorry Daemon!)  called rsyslog that logs messages from all sorts of processes and it&#8217;s quite easy to use in our programs as well. If we don’t do [&#8230;]</p>
The post <a href="https://learncgames.com/using-rsyslog-to-log/">Using rsyslog to log</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:790,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/OpenClipart-Vectors-30363\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1294359&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:791,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1294359&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:792,&quot;href&quot;:&quot;https:\/\/unix.stackexchange.com\/questions\/40533\/lubuntu-12-04-syslog-to-custom-file-not-var-log-syslog-but-var-log-mylog&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206185812\/https:\/\/unix.stackexchange.com\/questions\/40533\/lubuntu-12-04-syslog-to-custom-file-not-var-log-syslog-but-var-log-mylog&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-07 19:52:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-13 08:40:20&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-18 15:47:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 16:02:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 18:48:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-13 06:58:56&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 04:40:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 21:28:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 07:56:13&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 13:01:10&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-05 13:01:10&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:793,&quot;href&quot;:&quot;https:\/\/unix.stackexchange.com\/users\/19704\/giuspen&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206200312\/https:\/\/unix.stackexchange.com\/users\/19704\/giuspen&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-07 19:52:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 06:17:39&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-18 15:47:54&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 16:02:28&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-04 18:48:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-13 06:59:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-17 04:40:38&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 21:28:24&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 07:56:14&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-05 13:01:10&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-05 13:01:10&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_263" aria-describedby="caption-attachment-263" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-263" src="https://learncgames.com/wp-content/uploads/2020/03/computer-1294359_640-300x300.png" alt="logging" width="300" height="300" srcset="https://learncgames.com/wp-content/uploads/2020/03/computer-1294359_640-300x300.png 300w, https://learncgames.com/wp-content/uploads/2020/03/computer-1294359_640-150x150.png 150w, https://learncgames.com/wp-content/uploads/2020/03/computer-1294359_640.png 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-263" class="wp-caption-text">Image by <a href="https://pixabay.com/users/OpenClipart-Vectors-30363/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1294359">OpenClipart-Vectors</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1294359">Pixabay</a></figcaption></figure>
<p>I&#8217;m a great fan of logging; it helps you find out what&#8217;s happening in a program even if you can&#8217;t debug it. Linux, well Ubuntu has a service (sorry Daemon!)  called rsyslog that logs messages from all sorts of processes and it&#8217;s quite easy to use in our programs as well.</p>
<p>If we don’t do the next steps all the log messages will go into a file called syslog in <strong>/var/log</strong> and as this gets a lot of stuff it can grow reasonably quickly. But if you do the following steps, all logged output will instead go into</p>
<pre>/var/log/asteroids.log.</pre>
<p>From a terminal type the following command:</p>
<pre>sudo gedit /etc/rsyslog.d/30-debugging.conf</pre>
<p>Type this in and then save it (<em>click the Save button</em>) and close gedit.</p>
<pre>if $programname == 'asteroids' then /var/log/asteroids.log
&amp; ~</pre>
<p>Now run this command:</p>
<pre>sudo service rsyslog restart</pre>
<p>It should return immediately and means that any logging to syslog from a program called asteroids will from now on be redirected to /var/log/asteroids.log.</p>
<h2>Using rsyslog in a C program</h2>
<p>Here&#8217;s a short C Program that puts a message in the asteroids file.</p>
<pre><code class="language-c" data-line="">#include &lt;syslog.h&gt;
#include &lt;stdio.h&gt;

int main() {
    openlog(&quot;asteroids&quot;,LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);    
    syslog(LOG_INFO,&quot;Test Message %d&quot;,1);
    closelog();
}</code></pre>
<p>In a typical program you&#8217;d put the openlog statement in main() near the start and the closelog() near the end of main, and uses as many syslog() calls throughout your program as you need.</p>
<p>Now what I suggest you do is open another terminal and run this command before you run your main program. This will just sit there printing out each message line as it appears in asteroids.log. You can stop tail by hitting ctrl-c.</p>
<pre>tail -f /var/log/asteroids.log</pre>
<p>H/T to <a href="https://unix.stackexchange.com/questions/40533/lubuntu-12-04-syslog-to-custom-file-not-var-log-syslog-but-var-log-mylog" target="_blank" rel="noopener noreferrer">this StackExchange</a> answer from almost 8 years ago and answer by <a href="https://unix.stackexchange.com/users/19704/giuspen">giuspen</a>.</p>The post <a href="https://learncgames.com/using-rsyslog-to-log/">Using rsyslog to log</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">260</post-id>	</item>
	</channel>
</rss>
