├── .gitignore ├── package.json ├── README.md └── app.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | *.log 4 | *.pid 5 | test/child 6 | *.iml 7 | .idea/** 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pm2-syslog", 3 | "version": "2.1.0", 4 | "description": "Redirect PM2/apps logs to syslog", 5 | "main": "probe.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "dependencies": { 10 | "ain2": "^2.0.0", 11 | "pm2": "latest" 12 | }, 13 | "apps": [ 14 | { 15 | "name": "pm2-syslog", 16 | "script": "app.js" 17 | } 18 | ], 19 | "author": "Alexandre Strzelewicz", 20 | "license": "MIT" 21 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pm2-syslog 2 | 3 | Redirect all logs of PM2 + Apps managed into `/var/log/syslog` 4 | 5 | ## Configure OS 6 | 7 | Edit `/etc/rsyslog.conf` and uncomment: 8 | 9 | ``` 10 | # provides UDP syslog reception 11 | module(load="imudp") 12 | input(type="imudp" port="514") 13 | ``` 14 | 15 | Restart rsyslog: 16 | 17 | ``` 18 | $ sudo service rsyslog restart 19 | ``` 20 | 21 | ## Install module 22 | 23 | ``` 24 | # Install 25 | $ pm2 install pm2-syslog 26 | 27 | # Uninstall 28 | $ pm2 uninstall pm2-syslog 29 | ``` 30 | 31 | # License 32 | 33 | MIT 34 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | 2 | var pm2 = require('pm2'); 3 | var SysLogger = require('ain2'); 4 | var logger = new SysLogger({tag: 'pm2', facility: 'syslog'}); 5 | 6 | pm2.launchBus(function(err, bus) { 7 | bus.on('*', function(event, data){ 8 | if (event == 'process:event') { 9 | logger.warn('app=pm2 target_app=%s target_id=%s restart_count=%s status=%s', 10 | data.process.name, 11 | data.process.pm_id, 12 | data.process.restart_time, 13 | data.event); 14 | } 15 | }); 16 | 17 | bus.on('log:err', function(data) { 18 | logger.error('app=%s id=%s line=%s', data.process.name, data.process.pm_id, data.data); 19 | }); 20 | 21 | bus.on('log:out', function(data) { 22 | logger.log('app=%s id=%s line=%s', data.process.name, data.process.pm_id, data.data); 23 | }); 24 | }); 25 | --------------------------------------------------------------------------------