languages / node / configuration / logging-to-multiple-streams

Node Configuration - Logging To Multiple Streams

If you followed the standard install instructions, your application will send all logs from stdout and stderr to Timber. If you prefer to send your logs to multiple destinations Timber has built-in support for this. Using the attach function, you can attach multiple writable streams to stout and stderr.

Note: The attach() function is a replacement for install(). When manually attaching streams, you no longer need to use install().

How to use it

Example: Logging to Timber & a file

1
2
3
4
5
6
7
8
const fs = require('fs')
const timber = require('timber')

http_stream = new timber.transports.HTTPS('{{my-timber-api-key}')
file_stream = fs.createWriteStream('./app_logs', {flags: 'a'})

attach([http_stream, file_stream], process.stdout)
attach([http_stream, file_stream], process.stderr)
Questions?

Chat with us, just click the talk button in the bottom right of this page.

Chat with us
Sign Up

Log better and solve problems faster, today. Install in under a minute.

Sign Up