npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pino-stream

v0.1.0

Published

Stream pino logs to multiple transports

Downloads

9

Readme

pino-stream

Lead maintainer: alexandrevoilab

This module provides a child process utility for pino. It aims to be compatible with existing pino transports.

This is not a transport for pino by itself. Given a tranport list, it will spawn a new child process and run the transport inside the new process. This is similar to running node app.js | pino-transport.

Might not be production ready. This module as not been battle tested yet. See the TODO section.

Attribution

This module is inspired by pino-spawn and the following issues: pinojs/community#3 and atis--/pino-spawn#1.

Install

$ npm install pino-stream --save

Usage

Basic exemple usage with pino-elasticsearch and sole transport.

'use strict';

const pino_stream = require('pino-stream');

let pino = require('pino')(
  pino_stream(['pino-elasticsearch'])
);

Options

pino_stream() only takes one argument: an array of streams or modules to stream to. Every element in that array SHOULD be an object with the following properties.

The object MUST have only one of stream or module.

stream (stream.Writable)

A stream.Writable instance. Logs will be .pipe()ed directly to it.

module (string)

The name of a pino transport module. Not the require()ed module, just the name. pino-stream will spawn a new process to host the module and stream logs to it.

Should work with any pino transport listed on the official pino transport documentation.

args (array)

If the object describe a module, this will be the arguments passed to it.

See nodejs child_process.fork documentation.

Shorthands

Shorthand configurations are supported. An object will be used a stream and a string will be used as a module.

pino_stream([{
    module: 'pino-elasticsearch'
  }, {
    stream: process.stdout
  }
])

Is the same as

pino_stream(['pino-elasticsearch', process.stdout])

Exemples

One transport

Simple pipe pino-elasticsearch with no arguments.

'use strict';

const pino_stream = require('pino-stream');

let pino = require('pino')(
  pino_stream([{
    module: 'pino-elasticsearch'
  }])
);

Short:

'use strict';

const pino_stream = require('pino-stream');

let pino = require('pino')(
  pino_stream(['pino-elasticsearch'])
);

One transport and one stream

Pipe pino-elasticsearch with an external elasticsearch server and logs to stdout.

'use strict';

const pino_stream = require('pino-stream');

let pino = require('pino')(
  pino_stream([
    {
      module: 'pino-elasticsearch',
      args: ['--host', '10.20.30.40', '--index', 'myindex']
    },
    {
      stream: process.stdout
    }
  ])
);

Short:

'use strict';

const pino_stream = require('pino-stream');

let pino = require('pino')(
  pino_stream([
    {
      module: 'pino-elasticsearch',
      args: ['--host', '10.20.30.40', '--index', 'myindex']
    },
    process.stdout
  ])
);

One transport and pretty print

Simple pipe pino-elasticsearch with no arguments and pretty print to stdout.

'use strict';

const pino_stream = require('pino-stream');
const pretty = require('pino').pretty();

pretty.pipe(process.stdout);

let pino = require('pino')(
  pino_stream([
    {
      module: 'pino-elasticsearch'
    },
    {
      stream: pretty
    }
  ])
);

Short:

'use strict';

const pino_stream = require('pino-stream');
const pretty = require('pino').pretty();

pretty.pipe(process.stdout);

let pino = require('pino')(
  pino_stream(['pino-elasticsearch', pretty])
);

No transport

Useless, but it will not crash. All logs will be piped to process.stdout.

'use strict';

const pino_stream = require('pino-stream');

let pino = require('pino')(
  pino_stream()
);

TODO

PRs are welcome!

  • Add benchmarks
  • Add unit tests
  • Test on high loads
  • Test in backpressure situations
  • Restart crashed child process
  • Add a level filter for every output

License

MIT License