Socket
Book a DemoInstallSign in
Socket

pino-tee

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-tee

Tee pino logs into a file, with multiple levels

latest
Source
npmnpm
Version
0.3.0
Version published
Weekly downloads
1.3K
33.94%
Maintainers
4
Weekly downloads
 
Created
Source

pino-tee  Build Status

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 = require('pino');
const childProcess = require('child_process');
const stream = require('stream');

// Environment variables
const cwd = process.cwd();
const {env} = process;
const logPath = `${cwd}/log`;

// Create a stream where the logs will be written
const logThrough = new stream.PassThrough();
const log = pino({name: 'project'}, logThrough);

// Log to multiple files using a separate process
const child = childProcess.spawn(process.execPath, [
  require.resolve('pino-tee'),
  'warn', `${logPath}/warn.log`,
  'error', `${logPath}/error.log`,
  'fatal', `${logPath}/fatal.log`
], {cwd, env});

logThrough.pipe(child.stdin);

// Log pretty messages to console (optional, for development purposes only)
const pretty = pino.pretty();
pretty.pipe(process.stdout);
logThrough.pipe(pretty);

API

pinoTee(source)

Create a new tee instance from source. It is an extended instance of cloneable-readable.

Example:

const tee = require('pino-tee')
const fs = require('fs')
const stream = tee(process.stdin)
stream.tee(fs.createWriteStream('errors'), line => line.level >= 50)
stream.pipe(process.stdout)

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

Keywords

pino

FAQs

Package last updated on 29 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts