View NodeJS Application Logs Via Cron Tasks on Supervisor on Docker
<p>So the setup is...</p>

<p>Docker > Supervisor > Cron > NodeJS Task.</p>

<p>I am currently getting my supervisor to output it's log and error log to docker with the current supervisor setup.</p>

<pre><code>[program:cron]
command=cron -f
startsecs=10
priority=100
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
</code></pre>

<p>This shows the cron tasks running, ie</p>

<pre><code>app_1  |   'Supervisord is running as root and it is searching '
app_1  | 2016-08-26 12:54:30,519 CRIT Supervisor running as root (no user in config file)
app_1  | 2016-08-26 12:54:30,519 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
app_1  | 2016-08-26 12:54:30,536 INFO RPC interface 'supervisor' initialized
app_1  | 2016-08-26 12:54:30,536 CRIT Server 'unix_http_server' running without any HTTP authentication checking
app_1  | 2016-08-26 12:54:30,537 INFO supervisord started with pid 8
app_1  | 2016-08-26 12:54:31,542 INFO spawned: 'cron' with pid 11
app_1  | 2016-08-26 12:54:41,584 INFO success: cron entered RUNNING state, process has stayed up for &gt; than 10 seconds (startsecs)
</code></pre>

<p>However it doesn't show anything from my NodeJS application.</p>

<p>If i run my NodeJS application from the terminal with <code>nodejs index.js</code> i get <code>console.log</code> outputs as i would expect.</p>

<p>I know how to get my NodeJS output if i was running it from supervisor (it would be the same as cron setup above) however as im triggering it from cron it is different.</p>

<p>Now i suspect where I am going wrong is where i redirect my logs to with in my crontab...?</p>

<p>My crontab currently looks like the following (Running simple <code>ubuntu:14.04</code> docker image)...</p>

<pre><code>* * * * * cd /home/app &amp;&amp; nodejs /home/app/index.js &gt;&gt; /var/log/supervisor/supervisord.log 2&gt;&amp;1
</code></pre>

<p>This fire the app perfectly.</p>

<p>I can also view the logs by jumping into the container and running <code>cat /var/log/supervisor/supervisord.log</code>. It shows both the output of my app and also the cron output that i pasted above. However it doesn't appear on <code>docker-compose logs -f</code>.</p>

<p>Help much appreciated!</p>