PM2 module to forward PM2 logs to external syslog server
npm install pm2-syslog-sfPM2 module to forward PM2 process events and logs to an external syslog server.
This PM2 module automatically captures all PM2-managed process events and logs, forwarding them to your syslog server for centralized logging and monitoring. It listens to the PM2 event bus and forwards:
- Process lifecycle events (start, stop, restart, etc.)
- Application error logs (stderr output)
- Application standard logs (stdout output)
Install this module using PM2:
``bash`
pm2 install pm2-syslog-sf
Or install a specific version:
`bash`
pm2 install pm2-syslog-sf@1.0.3
- ✅ Automatic forwarding of all PM2 process events to syslog
- ✅ Captures both stdout and stderr from managed applications
- ✅ Structured log format with app name, process ID, and event details
- ✅ Can be disabled via environment variable
- ✅ Uses Unix domain socket for reliable local syslog delivery
- ✅ Minimal performance overhead
By default, logs are sent to the Unix socket address rsyslog. The module uses:
- Tag: pm2syslog
- Facility: (facility code 5)rsyslog
- Address: (Unix domain socket)
#### SKIP_LOCAL_SYSLOG
Set this environment variable to disable the module:
`bash`
export SKIP_LOCAL_SYSLOG=true
pm2 restart pm2-syslog-sf
When enabled, the module will stop itself and not forward any logs.
Process lifecycle events (start, stop, restart, etc.) are logged with WARNING level:
``
app=pm2 target_app=
Application errors are logged with ERROR level:
``
app=
Application standard output is logged with NOTICE level:
``
app=
- PM2: >=6.0.0 (uses PM2 6.0.13 with security fixes)
- Node.js: >=16.0.0
- Syslog Server: Must have a Unix socket at address rsyslog
To remove the module:
`bash`
pm2 uninstall pm2-syslog-sf
1. The module connects to PM2's internal event bus using pm2.launchBus()process:event
2. It listens for three types of events:
- - Process state changeslog:err
- - Error output from processeslog:out` - Standard output from processes
-
3. Events are formatted and sent to syslog via the ain2 library
4. Syslog server handles persistence, rotation, and forwarding
- ain2 (^3.0.0) - Syslog client library
- pm2 (^6.0.13) - Process manager
This version includes important security updates:
- PM2 upgraded from 4.5.6 to 6.0.13 (fixes multiple CVEs)
- Regular dependency updates for security patches
MIT
https://github.com/Silverfort/pm2-syslog-sf
Report issues at: https://github.com/Silverfort/pm2-syslog-sf/issues