Configuring centralized logging from Node.js apps

Papertrail can accept logs from any Node.js app using a regular text log file or the libraries winston or bunyan. Here’s how.

Method A: Use local log file

Have Node log to a file, then use remote_syslog2 to send its contents to Papertrail. Here’s how.

To make Node log to a file, either redirect its output or use the fs module. For example, to redirect stdout to myapp.log, start the daemon with:

nohup node myapp.js > myapp.log &

Method B: Send events from Node.js

Use the winston Papertrail transport to asynchronously transmit events from Node.js. See the transport README.

To log unhandled exceptions, see the winston documentation.

Alternatively, node-bunyan users can use the node-bunyan-syslog stream.