How to see PM2 restart history (node-pm2)
Asked Answered
D

2

11

Is it possible to see the restart log/history with PM2 app?

I saw my nodeJS app restarted a few times but no clue when.

I've checked pm2 documentation but no luck.

Despondency answered 2/12, 2016 at 2:28 Comment(1)
pm2.keymetrics.io/docs/usage/log-managementAzoic
V
23

PM2's own logs are streamed into the file ~/.pm2/pm2.log

Example commands for viewing:

  • cat ~/.pm2/pm2.log
  • tail -n 30 ~/.pm2/pm2.log - last 30 lines
  • watch -n 1 tail -n 30 ~/.pm2/pm2.log - last 30 lines, live-updated once per second

Example output:

2024-08-19T22:13:38: PM2 log: App [test-mem-limit:95] starting in -fork mode-
2024-08-19T22:13:38: PM2 log: App [test-mem-limit:95] online
2024-08-19T22:14:07: PM2 log: [PM2][WORKER] Process 95 restarted because it exceeds --max-memory-restart value (current_memory=4346691584 max_memory_limit=4294967296 [octets])
2024-08-19T22:14:07: PM2 log: Process 95 in a stopped status, starting it
2024-08-19T22:14:07: PM2 log: Stopping app:test-mem-limit id:95
2024-08-19T22:14:07: PM2 log: pid=3263791 msg=failed to kill - retrying in 100ms
2024-08-19T22:14:08: PM2 log: pid=3263791 msg=failed to kill - retrying in 100ms
2024-08-19T22:14:08: PM2 log: App [test-mem-limit:95] exited with code [0] via signal [SIGINT]
2024-08-19T22:14:08: PM2 log: pid=3263791 msg=process killed
2024-08-19T22:14:08: PM2 log: App [test-mem-limit:95] starting in -fork mode-
2024-08-19T22:14:08: PM2 log: App [test-mem-limit:95] online
Velmaveloce answered 2/12, 2016 at 18:16 Comment(1)
cat ~/.pm2/pm2.logTramontane
E
2

You can run the command: pm2 logs for an output of all logs, relating to running apps and their error logs.

The first log file in the window will be the default PM2 ones, for this kind of information.

Exurbanite answered 14/2, 2021 at 22:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.