Gathering detailed insights and metrics for pino-abstract-transport
Gathering detailed insights and metrics for pino-abstract-transport
Gathering detailed insights and metrics for pino-abstract-transport
Gathering detailed insights and metrics for pino-abstract-transport
npm install pino-abstract-transport
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
34 Stars
100 Commits
13 Forks
6 Watching
6 Branches
18 Contributors
Updated on 03 Sept 2024
JavaScript (95.25%)
TypeScript (4.48%)
Shell (0.27%)
Cumulative downloads
Total Downloads
Last day
3.2%
1,714,991
Compared to previous day
Last week
5.4%
8,914,573
Compared to previous week
Last month
21%
35,095,013
Compared to previous month
Last year
87.2%
298,505,093
Compared to previous year
1
7
Write Pino transports easily.
1npm i pino-abstract-transport
1import build from 'pino-abstract-transport' 2 3export default async function (opts) { 4 return build(async function (source) { 5 for await (let obj of source) { 6 console.log(obj) 7 } 8 }) 9}
or in CommonJS and streams:
1'use strict' 2 3const build = require('pino-abstract-transport') 4 5module.exports = function (opts) { 6 return build(function (source) { 7 source.on('data', function (obj) { 8 console.log(obj) 9 }) 10 }) 11}
Install the type definitions for node. Make sure the major version of the type definitions matches the node version you are using.
1npm i -D @types/node@16
Create a split2
instance and returns it.
This same instance is also passed to the given function, which is called
synchronously.
If opts.transform
is true
, pino-abstract-transform
will
wrap the split2 instance and the returned stream using duplexify
,
so they can be concatenated into multiple transports.
In addition to all events emitted by a Readable
stream, it emits the following events:
unknown
where an unparsable line is found, both the line and optional error is emitted.parse
an option to change to data format passed to build function. When this option is set to lines
,
the data is passed as a string, otherwise the data is passed as an object. Default: undefined
.
close(err, cb)
a function that is called to shutdown the transport. It's called both on error and non-error shutdowns.
It can also return a promise. In this case discard the the cb
argument.
parseLine(line)
a function that is used to parse line received from pino
.
expectPinoConfig
a boolean that indicates if the transport expects Pino to add some of its configuration to the stream. Default: false
.
You can allow custom parseLine
from users while providing a simple and safe default parseLine.
1'use strict' 2 3const build = require('pino-abstract-transport') 4 5function defaultParseLine (line) { 6 const obj = JSON.parse(line) 7 // property foo will be added on each line 8 obj.foo = 'bar' 9 return obj 10} 11 12module.exports = function (opts) { 13 const parseLine = typeof opts.parseLine === 'function' ? opts.parseLine : defaultParseLine 14 return build(function (source) { 15 source.on('data', function (obj) { 16 console.log(obj) 17 }) 18 }, { 19 parseLine: parseLine 20 }) 21}
You can pipeline multiple transports:
1const build = require('pino-abstract-transport') 2const { Transform, pipeline } = require('stream') 3 4function buildTransform () { 5 return build(function (source) { 6 return new Transform({ 7 objectMode: true, 8 autoDestroy: true, 9 transform (line, enc, cb) { 10 line.service = 'bob' 11 cb(null, JSON.stringify(line)) 12 } 13 }) 14 }, { enablePipelining: true }) 15} 16 17function buildDestination () { 18 return build(function (source) { 19 source.on('data', function (obj) { 20 console.log(obj) 21 }) 22 }) 23} 24 25pipeline(process.stdin, buildTransform(), buildDestination(), function (err) { 26 console.log('pipeline completed!', err) 27})
Setting expectPinoConfig
to true
will make the transport wait for pino to send its configuration before starting to process logs. It will add levels
, messageKey
and errorKey
to the stream.
When used with an incompatible version of pino, the stream will immediately error.
1import build from 'pino-abstract-transport' 2 3export default function (opts) { 4 return build(async function (source) { 5 for await (const obj of source) { 6 console.log(`[${source.levels.labels[obj.level]}]: ${obj[source.messageKey]}`) 7 } 8 }, { 9 expectPinoConfig: true 10 }) 11}
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 10/14 approved changesets -- score normalized to 7
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More