Tee pino logs into multiple files, according to the given levels. Works with any newline delimited json stream.
Install
npm i pino-tee -g
Usage
CLI
The following writes the log output of app.js
to ./all-logs
, while
writing only warnings and errors to `./warn-log:
node app.js | pino-tee warn ./warn-logs > ./all-logs
NodeJS
You can log to multiple files by spawning a child process:
const pino = ;const childProcess = ;const stream = ; // Environment variablesconst cwd = process;const env = process;const logPath = `/log`; // Create a stream where the logs will be writtenconst logThrough = ;const log = ; // Log to multiple files using a separate processconst child = childProcess; logThrough; // Log pretty messages to console (optional, for development purposes only)const pretty = pino;pretty;logThrough;
API
pinoTee(source)
Create a new tee
instance from source. It is an extended instance of
cloneable-readable
.
Example:
const tee = const fs = const stream = streamstream
stream.tee(dest, [filter])
Create a new stream that will filter a given line based on some parameters. Each line is automatically parsed, or skipped if it is not a newline delimited json.
The filter can be a function
with signature filter(line)
, where
line
is a parsed JSON object. The filter can also be one of the
pino levels either
as text or as a custom level number, in that case all log lines with
that level or greater will be written.
Acknowledgements
This project was kindly sponsored by nearForm.
License
MIT