PM2 logs show the process name and status by default, but not the time each event happened — you have to turn on timestamp logging separately
When you run Node.js applications with PM2, the logs tell you what your app is doing, but without timestamps you cannot tell when something happened. This matters when you are debugging a crash that occurred hours ago or tracking down when an error started. PM2 stores timestamps in its internal database, but the log output itself stays silent about time unless you configure it.
The fastest way is to add a single line to your PM2 configuration file. If you do not have one yet, you can create it in seconds. The timestamp will then appear at the start of every log line, showing the exact date and time in your system's local timezone.
Key Takeaways
- PM2 does not display timestamps in logs by default, even though it records the time internally.
- You enable timestamps by adding timestamp: true to your PM2 ecosystem configuration file.
- The configuration file is a JavaScript or JSON file that PM2 reads when you start your app, and you point to it with the pm2 start command.
- Once enabled, every log line will show the date and time in your system's local timezone at the beginning of the line.
- You can also view timestamped logs after the fact by checking PM2's internal log storage in your home directory.
Create or edit your PM2 ecosystem file
PM2 reads its settings from a configuration file, usually named ecosystem.config.js. If you already have one in your project, open it in a text editor. If not, create a new file with that name in your project root directory.
The file should contain a module.exports object that describes your application. Here is the minimum structure you need:
module.exports = { apps: [{ name: "my-app", script: "./app.js", timestamp: true }] }
Replace "my-app" with whatever you want to call your process, and replace "./app.js" with the path to your actual entry file. The timestamp: true line is what turns on the timestamp display. Save the file.
Start your app with the configuration file
Once your ecosystem file is saved, start your application by pointing PM2 to it. Open a terminal in your project directory and run:
pm2 start ecosystem.config.js
PM2 will read the configuration, start your app, and enable timestamps on all new log output. You should see the process start successfully. If PM2 is not found, you may need to install it first with npm install -g pm2 or use npx pm2 if you have it installed locally.
If your app was already running under PM2 with a different configuration, stop it first with pm2 stop my-app (using your actual app name), then start it again with the new config file.
View logs with timestamps
Once your app is running with timestamps enabled, view the logs by running:
pm2 logs
This shows a live stream of all logs from all your PM2 processes. Each line will now begin with a timestamp in the format [YYYY-MM-DD HH:MM:SS Z] or similar, depending on your system. The timestamp appears before the process name and the log message.
To see logs from only one process, use:
pm2 logs my-app
Replace my-app with your actual process name. The live log stream will continue until you press Ctrl+C to stop it.
Access saved logs from PM2's storage
PM2 keeps a permanent copy of all logs on your machine, separate from the live stream. These logs are stored in your home directory under .pm2/logs/. You can browse them directly if you need to search through old logs or check what happened before you started watching.
On Linux or Mac, the path is ~/.pm2/logs/. On Windows, it is usually C:\Users\[YourUsername]\.pm2\logs\. Inside that folder you will find files named after your processes, like my-app-error.log and my-app-out.log. Open these files in a text editor to search for specific timestamps or errors.
These stored logs do not automatically include timestamps unless you enabled the setting before the logs were written. If you want timestamps in the saved files going forward, make sure timestamp: true is in your configuration before restarting your app.
Troubleshooting timestamp issues
If you enabled timestamps but they are not appearing, check that your configuration file is actually being used. Run pm2 show my-app to see the current settings for your process. Look for the timestamp field in the output — it should say true.
If it says false or is missing, your app is not reading the ecosystem file. Stop the process with pm2 stop my-app, then start it again with pm2 start ecosystem.config.js instead of just pm2 start my-app. The full command matters — PM2 needs to be told which configuration file to use.
Another common issue is that old logs do not have timestamps even after you enable the setting. This is normal — the setting only affects new log lines written after you restart. Existing logs in the .pm2/logs/ folder will not change. If you need to see when old events happened, check the file modification time or look at the timestamps of other events around that time.
Frequently Asked Questions
Can I change the timestamp format to something other than the default?
PM2's built-in timestamp setting uses a fixed format and does not offer customization options through the configuration file. If you need a different format, you can add a logging library like Winston or Pino to your application code, which gives you full control over timestamp formatting. These libraries can write to files that PM2 then captures as logs.
Do timestamps show up in pm2 monit or the web dashboard?
The pm2 monit command and the PM2 web dashboard show real-time process status but do not display full log output with timestamps. Use pm2 logs to see timestamped log lines. The dashboard is better for watching CPU and memory usage, while the logs command is where you see what your app is actually printing.
What if I only want timestamps on error logs, not on all logs?
PM2 does not have a setting to enable timestamps only for errors. The timestamp: true setting applies to all output. If you need selective timestamping, add logging logic to your application code instead — have your error handler write to a separate file with timestamps, while letting normal output go to stdout without them.
Will enabling timestamps slow down my application?
No. Timestamps are added to the log output only, not to your application's execution. The performance impact is negligible — you are just adding a string to the beginning of each log line. This happens in PM2's logging system, not in your Node.js process itself.