Installations
npm install pino-abstract-transport
Developer
pinojs
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
20.16.0
NPM Version
10.8.1
Statistics
34 Stars
100 Commits
13 Forks
6 Watching
6 Branches
18 Contributors
Updated on 03 Sept 2024
Languages
JavaScript (95.25%)
TypeScript (4.48%)
Shell (0.27%)
Total Downloads
Cumulative downloads
Total Downloads
508,185,933
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
7
pino-abstract-transport
Write Pino transports easily.
Install
1npm i pino-abstract-transport
Usage
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}
Typescript usage
Install the type definitions for node. Make sure the major version of the type definitions matches the node version you are using.
Node 16
1npm i -D @types/node@16
API
build(fn, opts) => Stream
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.
Events emitted
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.
Options
-
parse
an option to change to data format passed to build function. When this option is set tolines
, 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 thecb
argument. -
parseLine(line)
a function that is used to parse line received frompino
. -
expectPinoConfig
a boolean that indicates if the transport expects Pino to add some of its configuration to the stream. Default:false
.
Example
custom parseLine
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}
Stream concatenation / pipeline
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})
Using pino config
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}
License
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
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
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/ci.yml:92
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/ci.yml:24
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/ci.yml:38
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/pinojs/pino-abstract-transport/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/pinojs/pino-abstract-transport/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/pinojs/pino-abstract-transport/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:51: update your workflow using https://app.stepsecurity.io/secureworkflow/pinojs/pino-abstract-transport/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/pinojs/pino-abstract-transport/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:68: update your workflow using https://app.stepsecurity.io/secureworkflow/pinojs/pino-abstract-transport/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:79: update your workflow using https://app.stepsecurity.io/secureworkflow/pinojs/pino-abstract-transport/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:95: update your workflow using https://app.stepsecurity.io/secureworkflow/pinojs/pino-abstract-transport/ci.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:63
- Info: 0 out of 5 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 3 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 26 are checked with a SAST tool
Score
4.2
/10
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