<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Flushing pm2 logs]]></title><description><![CDATA[<p dir="auto">While keeping MM alive with the <code>'pm2'</code> facility, all of the messages that MM generates will get logged through it. This allows you to be able to look at them with <code>'pm2 logs'</code>. However, this also means that that log file is continuously growing.</p>
<p dir="auto">For those of you running the newsfeed module, every once in a while that will throw an error if the feed item has a problem, such as missing a title. That error will repeat each time the newsfeed cycles back to the beginning. Over time, this creates a large amount of logged errors and the physical log file will be rather large.</p>
<p dir="auto">I was recently rather surprised to find the storage on my rpi at 99% full when I know that it should be closer to 48% … After scanning the file system I found the pm2 <em>MagicMirror specific log file</em> at several gigabytes in size. Left unchecked, this would’ve eventually filled the file system to 100% and caused the rpi itself to start failing in various, unpredictable ways.</p>
<p dir="auto">So, ontop of my post about <a href="https://forum.magicmirror.builders/topic/185/prereqs-on-your-raspberry-pi">maintenance on your rpi</a>, add this to the list: <code>'pm2 flush'</code>. Run that as the user that’s running the MM task (usually that’s the <code>'pi'</code> user) and it will automatically flush the log file for you.</p>
<p dir="auto">If you care to know where all this is stored on your rpi, it’s in the <code>'pi'</code> user’s folder, under a (hidden) folder called <code>'.pm2'</code>. Looking at its contents:</p>
<pre><code>pi/.pm2
├── conf.js
├── dump.pm2
├── logs
│   ├── MagicMirror-error-0.log
│   └── MagicMirror-out-0.log
├── module_conf.json
├── pids
│   └── MagicMirror-0.pid
├── pm2.log
├── pm2.pid
├── pub.sock
├── rpc.sock
└── touch

2 directories, 11 files
</code></pre>
<p dir="auto">The files you should look at are the <code>'MagicMirror-error'</code> and <code>'MagicMirror-out'</code> ones. Running <code>'pm2 flush'</code> will clear both of them.</p>
<p dir="auto">Edited to add: I forgot, another way to also see where the logs are, if by running <code>'pm2 show &lt;YOUR_MM_TASK&gt;'</code>. It should return a screen similar to this:</p>
<pre><code>pm2 show MagicMirror
 Describing process with id 0 - name MagicMirror 
┌───────────────────┬────────────────────────────────────────────┐
│ status            │ online                                     │
│ name              │ MagicMirror                                │
│ restarts          │ 1                                          │
│ uptime            │ 14s                                        │
│ script path       │ /home/pi/MagicMirror.sh                    │
│ script args       │ N/A                                        │
│ error log path    │ /home/pi/.pm2/logs/MagicMirror-error-0.log │
│ out log path      │ /home/pi/.pm2/logs/MagicMirror-out-0.log   │
│ pid path          │ /home/pi/.pm2/pids/MagicMirror-0.pid       │
│ interpreter       │ bash                                       │
│ interpreter args  │ N/A                                        │
│ script id         │ 0                                          │
│ exec cwd          │ /home/pi                                   │
│ exec mode         │ fork_mode                                  │
│ node.js version   │ N/A                                        │
│ watch &amp; reload    │ ✘                                          │
│ unstable restarts │ 0                                          │
│ created at        │ 2016-06-07T16:41:36.004Z                   │
└───────────────────┴────────────────────────────────────────────┘
</code></pre>
]]></description><link>https://forum.magicmirror.builders/topic/198/flushing-pm2-logs</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 23:04:20 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/198.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Jun 2016 16:31:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Flushing pm2 logs on Wed, 14 Mar 2018 06:23:31 GMT]]></title><description><![CDATA[<p dir="auto">I just want to add, that using <code>pm2 flush</code> in a script (for restart purposes) may not work as expected. The next operation will start immediately, before flush completes, and thus the new thread will already start writing to the file, blocking it from getting cleared.</p>
<p dir="auto">You need to wait for the entire thread to finish, like this:</p>
<pre><code class="language-bash">pm2 flush; pm2 start mm; echo "this doesn't clear the logs";

pm2 flush &amp;&amp;  pm2 start mm; echo "now it works";
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/36984</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/36984</guid><dc:creator><![CDATA[E3V3A]]></dc:creator><pubDate>Wed, 14 Mar 2018 06:23:31 GMT</pubDate></item><item><title><![CDATA[Reply to Flushing pm2 logs on Tue, 07 Jun 2016 22:01:58 GMT]]></title><description><![CDATA[<p dir="auto">Yes that’s another option, however personally I don’t use log rotates for a variety of reasons. In this case specifically, others have mentioned problems with it on the PM2 site.</p>
]]></description><link>https://forum.magicmirror.builders/post/1474</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/1474</guid><dc:creator><![CDATA[KirAsh4]]></dc:creator><pubDate>Tue, 07 Jun 2016 22:01:58 GMT</pubDate></item><item><title><![CDATA[Reply to Flushing pm2 logs on Tue, 07 Jun 2016 21:55:33 GMT]]></title><description><![CDATA[<p dir="auto">Automatically log rotate all applications logs managed by PM2<br />
<a href="https://github.com/pm2-hive/pm2-logrotate" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/pm2-hive/pm2-logrotate</a></p>
]]></description><link>https://forum.magicmirror.builders/post/1472</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/1472</guid><dc:creator><![CDATA[CGabo]]></dc:creator><pubDate>Tue, 07 Jun 2016 21:55:33 GMT</pubDate></item></channel></rss>