Pm2: Issues with configuring log path

Created on 3 Aug 2015  ยท  5Comments  ยท  Source: Unitech/pm2

OS: Ubuntu 14.04.2 LTS (on AWS)
Node version: 0.12.7
PM2 version: 0.14.5
Command: pm2 start ./bin/www.js -i -1 --name='process-name' --merge-logs -logs='/var/www/root/process-name/bin/logs' --log-date-format='YYYY-MM-DD HH:mm Z'

For what it's worth, this is in the "start" section of my package.json, so I'm calling the command via npm start. (Hence the single quotes.)

The end result of this command is that logs go... nowhere. They don't show up in either the default or expected directory.

Running pm2 show process-name gave me the following interesting table.

โ”‚ exec cwd          โ”‚ /var/www/root/process-name                    โ”‚
โ”‚ entire log path   โ”‚ /var/www/root/process-name/bin/logs        โ”‚
โ”‚ error log path    โ”‚ /home/ubuntu/.pm2/logs/process-name-error.log โ”‚
โ”‚ out log path      โ”‚ /home/ubuntu/.pm2/logs/process-name-out.log  |

If I set these things more manually (--output='/var/www/root/project-name/bin/logs/output.log'), then the paths get updated correctly in the pm2 show table, the "entire log path" variable doesn't show up, and the files go where they should:

โ”‚ exec cwd          โ”‚ /var/www/root/process-name                    โ”‚
โ”‚ error log path    โ”‚ /var/www/root/process-name/bin/logs/error.log โ”‚
โ”‚ out log path      โ”‚ /var/www/root/process-name/bin/logs/out.log 

Though I'm not sure how this manually-listed log file name will work with pm2-logrotate... I haven't seen a datestamp in a filename yet.

Also, if I try to list only the path, as the documentation kind of indicates I should (--output='/var/www/root/project-name/bin/logs/'), I get this table:

โ”‚ exec cwd          โ”‚ /var/www/root/process-name                    โ”‚
โ”‚ error log path    โ”‚ /var/www/root/process-name/bin/logs    โ”‚
โ”‚ out log path      โ”‚ /var/www/root/process-name/bin/logs  |

and the files go back to not showing up either in the specified folder or the default one.

Icebox Bug

All 5 comments

Do you have proper rights to create files and write on these directories ?

Belatedly: yes, I do. I changed my setup somewhat, creating a non-root user to handle this, and that user has full permissions to all the folders. (Well, the group the user is in does. But I can create folders and files while as that user.)

I notice today that trying to use the --logs flag gives me the error that that's not a recognized switch?

error: unknown option `--logs'

ETA: that was a copypaste error by me, of course the flag is --log.

Anyway, still experiencing the problem.

| label | data |
| --- | --- |
| status | online |
| name | process-name |
| id | 1 |
| path | /var/www/root/process-name/bin/www.js |
| args | |
| exec cwd | /var/www/root/process-name |
| entire log path | /var/www/root/process-name/bin/logs |
| error log path | /home/safeuser/.pm2/logs/process-name-error.log |
| out log path | /home/safeuser/.pm2/logs/process-name-out.log |

And again, there are no actual log files in this home/safeuser folder. Running -ls l on the .pm2 folder here gives me:

drwxrwxr-x 2 safeuser safeuser 4096 Oct 6 19:27 logs

so it's not like it doesn't belong to my currently logged in user.

ETA 2:

drwxrwsr-x 2 ubuntu phillynotifs 4096 Oct 6 19:13 logs

so I get this on the folder I actually _want_, /var/www/root/process-name/bin/logs. That's a different user, but a group my user is a member of. So... could theoretically be an issue. Ugh.

Wow that's an old thread.
Yet - same problems here.
PM v 2.5.0
Sys: Centos 6

Using
pm2 restart index -o /var/log/pm2/access.log -e /var/log/pm2/error.log --log-date-format="YYYY-MM-DD HH:mm Z"
and
pm2 restart index --log-date-format="YYYY-MM-DD HH:mm Z" --output="/var/log/pm2/access.log" --error="/var/log/pm2/error.log"
as http://pm2.keymetrics.io/docs/usage/log-management/ suggests.

Folder is there with 777 (for testing purposes) writes.

The result is the same - log folder do not change from default

and here I am in 2018 with the same problem...

I found out how to fix it. The problem only appears if you have already started the same app with pm2 once. Before starting the app with the new log paths as mentioned above, you need to type the command:

pm2 delete <pid>

You can find the pid by typing:

pm2 list

Was this page helpful?
0 / 5 - 0 ratings

Related issues

waygee picture waygee  ยท  4Comments

chaos-git picture chaos-git  ยท  3Comments

xzycn picture xzycn  ยท  3Comments

getvega picture getvega  ยท  3Comments

lefam picture lefam  ยท  3Comments