0

I'm new to PM2 and ubuntu-related issues.

I'm running an app using sudo with the syntax sudo pm2 start app.js --time.

However, when I tried to check the files in $HOME/.pm2/logs/app-error.log, I couldn't find any logs related to what I logged in the code. I believe sudo pm2 start is different from pm2 start, and the log files are only for the pm2 start.

My question is, how can I check the logs in sudo pm2?

Lucas.Pheliny
  • 85
  • 1
  • 8

4 Answers4

2

If you execute pm2 as the root user, the logs will be stored in /root/.pm2/logs/.

sudo executes commands as the root user, and that also entails that the home directory (referred to as $HOME or ~) that the command sees is the root user's home directory, which usually is /root.

So, if a program writes logs to the user's home directory, the location of the log files will depend on what user is executing that program.

snwflk
  • 3,341
  • 4
  • 25
  • 37
0

By default, pm2 will store log files in ~/.pm2/logs.

Ron Adin
  • 49
  • 8
  • Yes, I know about it. But the data stored by `sudo pm2` and `pm2` are two different data. And I don't know where to find those data from `sudo pm2` – Lucas.Pheliny Aug 14 '22 at 11:07
0

You can change the logs location like this:

Generate an ecosystem file:

pm2 ecosystem simple

Then edit the ecosystem file and add lines for changing the default location:

module.exports = {
  apps : [{
    name   : "My Application",
    script : "./myapp.js",
    error_file : "/var/log/pm2/myapp/err.log",
    out_file : "/var/log/pm2/myapp/out.log"
  }]
}

Alternatively, you can also use the command line:

pm2 start -n "My application" -o /var/log/pm2/myapp/out.log -e /var/log/pm2/myapp/err.log /path/to/my/application
Alaindeseine
  • 3,260
  • 1
  • 11
  • 21
0

I believe it's in /root/.pm2/logs/. Probably you haven't check them all using ls -a