Monday, 13 March 2017

How to print uncaughtexception log with date prefix in pm2

I come across an troubling problem, when the process started with pm2 broke down, but its uncaughtException's log will be wirtten via pm2 without date format. In other words, it make me have no idea when the process broke down.

To description the problem simply, I will give a two lines js file:

console.log(xxx); console.log('over');

The code of err.js

Then I start err.js with pm2:

pm2 start err.js --log-date-format "YYYY-MM-DD HH:mm"

Unfortunately,the error log is printed without date format:

ReferenceError: xxx is not defined
    at Object.<anonymous> (F:\temp\sodu_build\err.js:1:75)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Function._load (d:\Users\sunny\AppData\Roaming\nvm\v6.9.2\node_modules\pm2\node_modules\.0.6.8@pmx\lib\transaction.js:62:21)
    at Object.<anonymous> (d:\Users\sunny\AppData\Roaming\nvm\v6.9.2\node_modules\pm2\lib\ProcessContainerFork.js:52:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)

The output of error log

This issue can be reproduced easily. And the error log is very important for developers , we have to known when the app broke down. I have no idea why not the pm2 maintainer add the support of the date format of error log.

I use the latest version of 2.4.2.



via yunnysunny

No comments:

Post a Comment