PM2: How to disable logging to disk but continue realtime log to console?

  Kiến thức lập trình

I want to run a NodeJS app with PM2 and continue to see realtime logs written to the console when running pm2 log, but no logs should be written to disk. I’m running a RPi on SD card and want to avoid unnecessary wear on the card. I only want to view realtime log messages on demand and do not need any log history saved to disk.

I tried pm2 start app.js --out-file /dev/null --error-file /dev/null but then no logs are written to console either: pm2 log doesn’t output realtime logs.

Then I tried pm2 start app.js --log-type pipe and again no realtime logs are written to console.

Again I want realtime log messages to be written to console when pm2 log is running, but no logs written to disk.

This may not be possible… if pm2 log simply executes a tail -f on the log files, then it would be necessary to write the log files in order to see console output. However, if the app’s console output could be redirected another way, that would be fine too, as long as disk write is avoided.

LEAVE A COMMENT