Chris's Wiki :: blog/programming/LoggingAndStreams Commentshttps://utcc.utoronto.ca/~cks/space/blog/programming/LoggingAndStreams?atomcommentsDWiki2011-04-07T10:46:08ZRecent comments in Chris's Wiki :: blog/programming/LoggingAndStreams.From 80.254.147.84 on /blog/programming/LoggingAndStreamstag:CSpace:blog/programming/LoggingAndStreams:d3ee2f103490fa4de0f635ef9d13d60267549464From 80.254.147.84<div class="wikitext"><p>Redirect stderr to a named pipe, read from the named pipe into your rotating/syslogging program of choice.</p>
</div>2011-04-07T10:46:08ZFrom 82.145.208.209 on /blog/programming/LoggingAndStreamstag:CSpace:blog/programming/LoggingAndStreams:6d1864b1c99dba501c4cffa821b4b73026e69749From 82.145.208.209<div class="wikitext"><p>hello, when yiu want to use copy truncate, you need to have the application appending. so using >>logfile instead of >logfile. some older tomcat had it wrong for catalina.out log (basicaly stdout logging) and it made problems.</p>
<p>-jhr.</p>
</div>2011-04-07T05:38:22ZBy Chris Siebenmann on /blog/programming/LoggingAndStreamstag:CSpace:blog/programming/LoggingAndStreams:b4039bfca7a7295fdfd5d9bfbcdfd091d5b08514Chris Siebenmann<div class="wikitext"><p>Copying and truncating log files suffers from two problems: you can lose
records (and you will if this is an active daemon) and you have to trust
that the program and the system are not going to malfunction in the face
of having standard error truncated on them (<a href="https://utcc.utoronto.ca/~cks/space/blog/unix/WhyUseSparseFiles">cf</a>).</p>
</div>2011-04-06T14:45:02ZFrom 85.12.213.105 on /blog/programming/LoggingAndStreamstag:CSpace:blog/programming/LoggingAndStreams:94ac8d218cbf53d6ab648794b55c4ad3b8ecc950From 85.12.213.105<div class="wikitext"><p>No one mentioned stdout/stderr redirection capabilities in systemd, while it's pretty much the only place where it seemed to be useful to me.</p>
<p>Lots of simple apps that don't do much logging can be told to just log to stderr (and it usually coincides nicely with non-forking mode, which is preferrable when running stuff in systemd), and default logging (syslog, or terminal, if you need to debug something early) target will catch the output instead of creating lots of unwatched and unchecked log files.</p>
</div>2011-04-06T14:29:34ZFrom 77.23.49.79 on /blog/programming/LoggingAndStreamstag:CSpace:blog/programming/LoggingAndStreams:113f9f35c0d2fec58b54f6812565db782537b782From 77.23.49.79<div class="wikitext"><p>I don't quite agree with you about:</p>
<blockquote><p>"we cannot run your program as just 'program 2>/var/log/program', because that would give us no way to rotate /var/log/program."</p>
</blockquote>
<p>At least in Linux the logrotate program offers the "copytruncate" configuration option, which can handle such cases. I'd be surprised if other OSs wouldn't offer a similar option.</p>
</div>2011-04-06T14:21:11ZBy Chris Siebenmann on /blog/programming/LoggingAndStreamstag:CSpace:blog/programming/LoggingAndStreams:dc4d16215e56215e880e10f64745bcaa156acd9aChris Siebenmann<div class="wikitext"><p>One part of the answer about <code>logger</code> is sufficiently long and involved
that I wrote an entry about it, <a href="https://utcc.utoronto.ca/~cks/space/blog/programming/SyslogVsStderr">SyslogVsStderr</a>.</p>
<p>The other part is that you have to trust both <code>logger</code> and the program
feeding it a lot. For example, you have to trust that both sides are
doing unbuffered IO, so that messages go through the pipe immediately
and as fast as possible. This is probably true, but if you're going to
build a logging solution you need to check.</p>
<p>(And then you need to be wary of people changing either side out from
underneath you, because after all they never imagined that someone was
using <code>logger</code> this way and that it mattered etc etc.)</p>
</div>2011-04-04T21:08:14ZFrom 138.246.23.74 on /blog/programming/LoggingAndStreamstag:CSpace:blog/programming/LoggingAndStreams:24cf9d38324ce796d6eec97d3a73902acb12dda1From 138.246.23.74<div class="wikitext"><p>Plenty of such tools exist:</p>
<ul><li><a href="http://smarden.org/runit/svlogd.8.html">http://smarden.org/runit/svlogd.8.html</a></li>
<li><a href="http://cr.yp.to/daemontools/multilog.html">http://cr.yp.to/daemontools/multilog.html</a></li>
<li><a href="http://httpd.apache.org/docs/2.0/programs/rotatelogs.html">http://httpd.apache.org/docs/2.0/programs/rotatelogs.html</a></li>
<li><a href="http://cronolog.org/usage.html">http://cronolog.org/usage.html</a></li>
</ul>
<p>Also, can you elaborate what the problem with piping to logger is?
The implementations I saw fgets a line and syslog it, which seems fine.</p>
</div>2011-04-04T11:54:35Z