What is the default location of PM2 log files?
Asked Answered
M

6

71

I'm trying to find out where PM2 saves the log files by default?

I'm working with a Linux Ubuntu 16.04 server and I've installed it globally with npm i pm2 -g.

Mainly answered 24/4, 2019 at 10:34 Comment(0)
H
106

pm2 saves logs to $HOME/.pm2/logs/XXX-err.log by default, where XXX is your pm2 app name

Hoboken answered 24/4, 2019 at 10:43 Comment(7)
why doesn't pm2 saves the log date and time? i can't see it in ~/.pm2/logs/app-err.logHegel
pm2 also saves timestamp, you need to first run command: pm2 start app.js --time and then can display logs with timestamp attached in prefix by running command: pm2 logs --format or pm2 logs --jsonHoboken
neither --format nor --json works for me. I tried pm2 start api --time and then pm2 logs api --format and no logs are displaying on screenHegel
Syntax err:Remove your 'app name' from following command pm2 logs api --formatHoboken
so i need to start the application without using its name? i'll give a try. thank you for the help! :)Hegel
now it's working. but without using --format flag. i just started the application using pm2 start api --time and then pm2 logs api. now i can see the time prefixing the logs. thank you again!Hegel
Where can I see the error message/error tree in pm2 logs. ~/.pm2/logs/xxx.err.log only shows 500 status but doesn't show errorInflorescence
G
30

I wanted to see the logs for different processes. There is a console-based UI for this:

pm2 monit

Extra tips for pm2 newbies:

  • Launch multiple, co-ordinated, instance per cpu core with: pm2 start myApp.js -i max
    • Beware the 'js' example of cluster configuration; it didn't work for me. Try 'json' instead.
  • By default, you need to leave user logged in to keep cluster running
  • Handy commands:
    • pm2 start all (also stop / delete)
    • pm2 list
Garnes answered 24/2, 2020 at 18:30 Comment(5)
This has nothing to do with the original question.Sideshow
This answer is related to the question. If someone wants to inspect logs then this answer is helpful.Garnes
The question is "What is the default location of PM2 log files?". Does this answer give the default location of PM2 log files? No. It's helpful, sure, but not if you're looking for an answer to the original question.Sideshow
@Sideshow I just want to check the logs of my app, this answer was very helpful for me, and I know I'm not the only one, that's why this answer has a lot of upvoteAshien
@Ashien yes, that’s what I wrote: it’s useful, but not for the original question. I had the same question as OP, and this answer was just noise to me.Sideshow
V
18

Type pm2 log in a shell and you get an overview of the last 15 log lines and the last 15 error lines in realtime. At the top of these log lines, the location of your logfile is shown. You can also type pm2 log --lines 1000 to show more lines, in this case 1000.

$pm2 log
$pm2 log --lines 500

To exit, just type ctrl-c

Venal answered 4/7, 2020 at 17:46 Comment(0)
P
11

A great way to get information on logfile location (and other useful info) is to do a "pm2 describe" on the process that you have running. You can use this method running pm2 as a standard user or if you use it as sudo pm2.

Get the name or id of the process

pm2 list

use describe by either using the id# or the name

pm2 describe 0
Pontine answered 25/11, 2020 at 19:3 Comment(0)
W
7

pm2 has two types of log files for every app that it runs, an error log file and an out log file.

The error logs are saved to $HOME/.pm2/logs/XXX-error.log or ~/.pm2/logs/XXX-error.log

While the out logs are saved to $HOME/.pm2/logs/XXX-out.log or ~/.pm2/logs/XXX-access.log.

Where XXX is the name of your app.

Wojak answered 21/12, 2020 at 12:8 Comment(0)
S
2
pm2 status

it will show your apps name or id say above command return apps name PN and id : 0 Then you can write following command in console

pm2 describe 0

Or

pm2 describe 

In return you will see 2 tables where you can see as below

| script path       │ /root/.nvm/versions/node/v7.3.1/bin/npm           │
│ script args       │ --prefix /opt/da/pn run start │
│ error log path    │ /root/.pm2/logs/pn-node-error-0.log       │
│ out log path      │ /root/.pm2/logs/pn-node-out-0.log      

You are actually looking for out log path. error log path will be shown if you configured

Solipsism answered 25/1, 2024 at 14:53 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.