WHERE PM2 LOGS ARE STORED
PM2 is a process manager for Node.js applications that helps monitor and maintain them. Its logging capabilities allow you to track the performance and behavior of your apps. Understanding where PM2 logs are stored is crucial for troubleshooting issues, debugging errors, and gaining insights into your applications' operation.
Log File Locations
Default Location:
- Unix-based Systems:
/var/log/pm2/ - Windows Systems:
%USERPROFILE%\AppData\Local\pm2\logs\
- Unix-based Systems:
User-Defined Location:
- PM2 allows you to specify a custom log directory using the
--log-dirflag when starting your application. - The logs will be stored in the specified directory.
- PM2 allows you to specify a custom log directory using the
Log File Naming Convention:
- PM2 uses the following naming convention for its log files:
pm2-<app_name>-out.log: Contains standard output (stdout) logs.pm2-<app_name>-error.log: Contains standard error (stderr) logs.pm2-<app_name>.log: Contains combined stdout and stderr logs.
- PM2 uses the following naming convention for its log files:
Accessing Log Files
Local Access:
- On Unix-based systems, you can use the command
sudo cat /var/log/pm2/<app_name>*.logto view the logs. - On Windows systems, you can open the log files from the
%USERPROFILE%\AppData\Local\pm2\logs\directory.
- On Unix-based systems, you can use the command
Remote Access:
- If you are running PM2 on a remote server, you can use SSH to connect to the server and access the log files as mentioned above.
Log Rotation
PM2 automatically rotates log files when they reach a certain size or age. By default, the maximum log file size is 10 MB, and the maximum age is one day.
Customizing Log Settings
Changing Log Level:
- You can adjust the log level by setting the
--log-levelflag when starting your application. - Possible log levels include
error,warn,info, anddebug.
- You can adjust the log level by setting the
Changing Log Format:
- PM2 supports various log formats, including JSON, pretty-print, and raw.
- You can specify the desired format using the
--log-typeflag.
Enabling/Disabling Timestamps:
- You can control whether timestamps are included in the logs using the
--log-timestampflag.
- You can control whether timestamps are included in the logs using the
Conclusion
Understanding where PM2 logs are stored and how to access them is essential for monitoring and maintaining your Node.js applications. By leveraging PM2's logging capabilities, you can gain valuable insights into the performance, behavior, and errors of your apps, enabling you to troubleshoot issues and ensure smooth operation.
FAQs
Can I change the default log file location?
- Yes, you can specify a custom log directory using the
--log-dirflag when starting your application.
- Yes, you can specify a custom log directory using the
How can I view PM2 logs remotely?
- You can use SSH to connect to the remote server and access the log files as mentioned in the article.
How do I change the log level?
- You can adjust the log level by setting the
--log-levelflag when starting your application.
- You can adjust the log level by setting the
Can I change the log format?
- Yes, PM2 supports various log formats, which you can specify using the
--log-typeflag.
- Yes, PM2 supports various log formats, which you can specify using the
How can I enable or disable timestamps in the logs?
- You can use the
--log-timestampflag to control whether timestamps are included in the logs.
- You can use the

Leave a Reply