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.
This module is inspired by pino-spawn and the following issues: pinojs/community#3 and atis--/pino-spawn#1.
$ npm install pino-stream --save
Basic exemple usage with pino-elasticsearch and sole transport.
Note, you have to npm install pino-elasticsearch
before.
'use strict';
const pino_stream = require('pino-stream');
let pino = require('pino')(
pino_stream(['pino-elasticsearch'])
);
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
.
A stream.Writable
instance. Logs will be .pipe()
ed directly to it.
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.
If the object
describe a module, this will be the arguments passed to it.
See nodejs child_process.fork documentation.
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])
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'])
);
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
])
);
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])
);
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()
);
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