What is the default location of PM2 log files?

67,236

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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

Solution 5

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.

Share:
67,236

Related videos on Youtube

Dave
Author by

Dave

SUMMARY ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ I’m a Full Stack Software Engineer who has been doing software development. I work simultaneously in the development of web applications and server-side features, such as building powerful and efficient APIs. TECHNOLOGIES ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ Here is a quick list of some of the technologies I've worked on in the recent past. JavaScript: Express, Node.js, Sails.js, VueJS, ReactJS, React Native, Redux, KoaJS .NET: C#, DevExpress Tools Databases: MongoDB, MySQL, Oracle, PostgreSQL, Redis, MS-SQL Server Deployment: AWS, Heroku, Vagrant Servers: Apache, Nginx OS: Linux, OS X, Windows Development Methods: Agile, SCRUM Other: PHP, HTML5, CSS, Python ROLES ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ Here are a few different ways I can help. ♨ As an Architect You need help architecting a new product from scratch, or improving an existing one to make it more current, performant, scalable or maintainable. ♨ As a Developer You need help leading a development team, or are looking for an independent contributor to help out with development. ♨ As a Problem Solver You have a varying list of ever changing software engineering needs and need someone who can do a bit of everything!

Updated on December 23, 2020

Comments

  • Dave
    Dave over 3 years

    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.

  • Renan Coelho
    Renan Coelho over 4 years
    why doesn't pm2 saves the log date and time? i can't see it in ~/.pm2/logs/app-err.log
  • varundhariyal
    varundhariyal over 4 years
    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 --json
  • Renan Coelho
    Renan Coelho over 4 years
    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 screen
  • varundhariyal
    varundhariyal over 4 years
    Syntax err:Remove your 'app name' from following command pm2 logs api --format
  • Renan Coelho
    Renan Coelho over 4 years
    so i need to start the application without using its name? i'll give a try. thank you for the help! :)
  • Renan Coelho
    Renan Coelho over 4 years
    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!