<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>daemontools — Little Step</title>
    <link>https://rex.writeas.com/tag:daemontools</link>
    <description></description>
    <pubDate>Sat, 14 Nov 2026 00:47:06 +0000</pubDate>
    <item>
      <title>Log rotation</title>
      <link>https://rex.writeas.com/log-rotation?pk_campaign=rss-feed</link>
      <description>Recently I got a problem for log rotation. We run an open source service on our cloud, and it works well for the functions, but for engin...</description>
      <content:encoded><![CDATA[<p>Recently I got a problem for log rotation.</p>

<p>We run an open source service on our cloud, and it works well for the functions, but for engineering side, it does not suppport log rotation.</p>

<p>And furthermore, the maintainer think the function is trivial and don&#39;t even plan to support this function.</p>

<p>We have at least two solutions for this problem, a) simply change the source code, and add this functionality, and b) use external tools.</p>

<p>The solution a) is straightforward, and we only need to add file size and number check when write logs to file.</p>

<p>But it will involve merge problems when upstream updates, and not even metion the code license problem. So solution a) is my last one.</p>

<p>For solution b), the most common one is to use logrotated service on Linux servers.</p>

<p>Logrotated runs periodically and when file size reaches the size, it renames the file, and sends signal to the process to create new file, and remove old log files.</p>

<p>The very popular nginx use this solution for log rotation.</p>

<p>To use this solution, the service must support signals for log re-create, while my one doesn&#39;t.</p>

<p>Until I found <a href="https://cr.yp.to/daemontools/multilog.html" rel="nofollow ugc">multilog</a>, my problem is solved.</p>

<p>Multilog is like tool <a href="https://man7.org/linux/man-pages/man1/tee.1.html" rel="nofollow ugc">tee</a> which read from stdout and write to stdout and files, it reads from stdout and write to files with more features such as filer, timestamp adding, etc.</p>

<p>My service doesn&#39;t support logrotation, but it can write logs on stdout.</p>

<p>With this I can use the below command to archive the goal of logrotation:</p>

<pre><code class="language-shell"># s&lt;size bytes&gt;: max size for file, 100mb for this case
# n&lt;file number&gt;: keep at least &lt;number&gt; of backups
my_app 2&gt;&amp;1 | multilog s100000000 n10 /var/log/app
</code></pre>

<p>Multilog is part of <a href="https://cr.yp.to/daemontools.html" rel="nofollow ugc">daemontools</a>, which is a nice package, and worth a look.</p>

<p>#log <a href="https://rex.writeas.com/tag:multilog" class="hashtag" rel="nofollow ugc"><span>#</span><span class="p-category">multilog</span></a> <a href="https://rex.writeas.com/tag:daemontools" class="hashtag" rel="nofollow ugc"><span>#</span><span class="p-category">daemontools</span></a></p>
]]></content:encoded>
      <guid>https://rex.writeas.com/log-rotation</guid>
      <pubDate>Mon, 30 Nov 2020 15:39:52 +0000</pubDate>
    </item>
  </channel>
</rss>