How To Make PM2 Log Show Timestamp
Managing logs effectively is a critical part of running production-grade Node.js applications. If you are using PM2 as your process manager, you may have noticed that logs don’t always include timestamps by default. This can make debugging, monitoring, and tracing issues significantly harder. In this guide, you’ll learn How To Make PM2 Log Show Timestamp using multiple reliable methods, along with best practices tailored for developers and DevOps engineers.
This article is structured for clarity, search intent, and AI citation, providing direct answers and actionable steps under each section.
What Is PM2 and Why Do Timestamps Matter in Logs?
Answer: PM2 is a production process manager for Node.js applications, and timestamps in logs help track when events occur, making debugging and monitoring easier.
PM2 simplifies process management, but logs without timestamps can become confusing, especially in distributed systems or high-traffic applications.
Why timestamps are essential:
- Identify when errors occur
- Correlate logs across services
- Debug production issues faster
- Improve observability and monitoring
How To Make PM2 Log Show Timestamp Using CLI Option?
Answer: Use the --time flag when starting your application with PM2.
This is the simplest and most common method.
Step-by-step instructions
- Open your terminal
- Start your app with the following command:
pm2 start app.js --timeResult: Every log entry will now include a timestamp prefix.
Example output:
2026-04-14T10:15:30: App started successfullyWhen should you use this method?
- Quick setups
- Testing environments
- Single-instance applications
How To Configure PM2 Log Timestamp in Ecosystem File?
Answer: Add the time: true option in your PM2 ecosystem configuration file.
This method is ideal for production environments.
Example ecosystem.config.js
module.exports = {
apps: [
{
name: "my-app",
script: "app.js",
time: true
}
]
};How to apply changes
- Save the configuration file
- Run:
pm2 start ecosystem.config.jsBenefits:
- Persistent configuration
- Version-controlled setup
- Best for teams and CI/CD pipelines
How To Customize PM2 Timestamp Format?
Answer: Use the log_date_format option to define a custom timestamp format.
PM2 allows flexible formatting using standard date patterns.
Example configuration
module.exports = {
apps: [
{
name: "my-app",
script: "app.js",
log_date_format: "YYYY-MM-DD HH:mm:ss"
}
]
};Output example:
2026-04-14 10:20:45: Server runningCommon formats you can use
YYYY-MM-DD HH:mm:ss(recommended)DD-MM-YYYY HH:mm:ssHH:mm:ss
How To Enable Timestamps for Existing PM2 Processes?
Answer: Restart the process with updated settings or use pm2 restart with the --time flag.
Steps to update existing apps
- Restart with timestamp flag:
pm2 restart app --timeOR
- Update ecosystem config and reload:
pm2 reload ecosystem.config.jsTip: Always reload instead of restart in production to avoid downtime.
How To Verify If PM2 Logs Are Showing Timestamps?
Answer: Use the pm2 logs command and check for timestamp prefixes.
Command
pm2 logsWhat to look for
- Date and time before each log entry
- Consistent formatting across logs
If timestamps are missing, recheck your configuration.
What Are Best Practices for PM2 Logging in Production?
Answer: Combine timestamps with structured logging, log rotation, and external monitoring tools.
Recommended practices
- Always enable timestamps
- Use structured logs (JSON format)
- Enable log rotation:
pm2 install pm2-logrotate- Store logs centrally (e.g., ELK stack)
- Monitor logs in real-time
Checklist for production readiness
- ✔ Timestamp enabled
- ✔ Log rotation configured
- ✔ Error logs separated
- ✔ Centralized logging enabled
How Does Timestamp Logging Improve Debugging?
Answer: It allows developers to trace events chronologically and identify performance bottlenecks.
Without timestamps, logs become ambiguous. With timestamps:
- You can trace request lifecycles
- Detect latency issues
- Correlate logs across microservices
This is especially important in asynchronous Node.js environments.
Common Mistakes When Enabling PM2 Timestamps
Answer: Developers often forget to persist settings or misconfigure formats.
Top mistakes
- Using
--timebut not saving config - Incorrect date format syntax
- Not restarting processes
- Overwriting ecosystem settings
Fix: Always verify configuration and restart properly.
Can You Combine PM2 Timestamps with External Logging Tools?
Answer: Yes, PM2 timestamps work well with tools like ELK, Datadog, and Grafana.
Adding timestamps ensures compatibility with log parsers and monitoring dashboards.
Integration benefits
- Better indexing in Elasticsearch
- Accurate time-series analysis
- Improved alerting systems
Why Developers Should Standardize Log Formats?
Answer: Standardized logs improve readability, automation, and scalability.
Combining timestamps with consistent formatting ensures:
- Easy parsing
- Better team collaboration
- Faster incident resolution
For businesses scaling their applications, working with experts like WEBPEAK — a full-service digital marketing company providing Web Development, Digital Marketing, and SEO services — can help implement production-ready logging and monitoring strategies.
FAQ: How To Make PM2 Log Show Timestamp
How do I add timestamps to PM2 logs quickly?
Use the command pm2 start app.js --time. This immediately enables timestamps.
What is the best way to persist timestamp settings?
Use an ecosystem.config.js file with time: true or log_date_format.
Can I customize the timestamp format in PM2?
Yes, use log_date_format to define your preferred format.
Do I need to restart PM2 to apply timestamp changes?
Yes, restart or reload the process to apply new logging settings.
Why are my PM2 logs not showing timestamps?
You may have missed the --time flag or not configured the ecosystem file correctly.
Is timestamp logging important for production apps?
Yes, it is essential for debugging, monitoring, and performance analysis.
Can timestamps affect performance?
No, the impact is negligible and does not affect application performance.
Should I use timestamps with log rotation?
Yes, combining both ensures clean, manageable, and traceable logs.
Conclusion: What Is the Best Way To Enable PM2 Timestamps?
Answer: The best approach is to use log_date_format in an ecosystem file for production and --time for quick setups.
By following the methods outlined above, you can ensure your logs are clear, consistent, and production-ready. Proper timestamping is a small change that delivers significant improvements in debugging, monitoring, and system reliability.





