pm2

How to see PM2 restart history (node-pm2)


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.


Solution

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

    Example commands for viewing:

    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