{"name":"pino-abstract-transport","version":"0.2.0","description":"Write Pino transports easily","main":"index.js","scripts":{"prepare":"husky install","test":"standard | snazzy && tap test/*.test.js","test-ci":"standard | snazzy && tap test/*.test.js --coverage-report=lcovonly"},"repository":{"type":"git","url":"git+https://github.com/pinojs/pino-abstract-transport.git"},"keywords":["pino","transport"],"author":{"name":"Matteo Collina","email":"hello@matteocollina.com"},"license":"MIT","bugs":{"url":"https://github.com/pinojs/pino-abstract-transport/issues"},"homepage":"https://github.com/pinojs/pino-abstract-transport#readme","dependencies":{"split2":"^3.2.2"},"devDependencies":{"husky":"^6.0.0","snazzy":"^9.0.0","standard":"^16.0.3","tap":"^15.0.2"},"gitHead":"9b74d181db8c02cc217bb92c3a315f26ac858205","_id":"pino-abstract-transport@0.2.0","_nodeVersion":"14.16.0","_npmVersion":"6.14.11","_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"dist":{"integrity":"sha512-40sX7xrzDXsrUYr65brL0+bLm6rpZ+wCujDeeBmmZ/y5RVcPdVQsmz0bBe8NtTpELgmzmKwRRPVj1lvKjgFVHw==","shasum":"e27d58d7bb16735c587c54e1d4efecc2cce27436","tarball":"http://registry-npm.ywwl.com/pino-abstract-transport/download/pino-abstract-transport-0.2.0.tgz","fileCount":8,"unpackedSize":14548,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgpOylCRA9TVsSAnZWagAAYoEQAIs3kRc0oQ0xHgGSItgs\nl8Q3TuAes+gMmXT+2GoJM44PaFxnU2SM1u34l6WdibBuGXDakl+rEpZF/oG5\npmTU91kuVu9TYmrXKXfpYqGnCdL42sy/d+luQQcuSapESEA5jiXDbte5rXB0\n7D/Kdp5b3590IjbVs+e5aE7tKaX1igJaJLPIROolra+UyBJ5oYK5GhZgIRP4\npcNvqli0kvjw44doDJk8mLHQPaPd0I2PDPRmcfj9PWR8YMmjMV1kk0sZqyUM\nDx4iP/Z5psVLlV3N2+fU/cVr6GEvwln9b0pVOmXIx5ddTNlrRWrGJzSWg10E\ncNvbngiE3c4XUGwReFmlKl3ZWfn4ToTY9hsruVywxNtEyf9h1jpQWdMkNqd/\nUslatiKXYncO7Ub927+8oe8ACpeYHlSOGHT5OIs8VbixFAh0u0GlAdfLA9ds\n2kWIzkkRBqhC0wa2eI60VxKYoO6YQfW7dSH9H15qAXvrTnVRULIiLlAJCN6A\nrbzgibw8/S6CbH4SSX06cX70h30yeC0NXUI6VV8zRUgFYM3q8SPBrpZPXBfp\nnnP4fVsRiwfbN32dXruPRTOAGtiL1L/hzws75FjaxzcMKv1VQlFECRCQjBwL\nSVqkBuxrcOYtXForKDurLeMYYo+q2P1jdRpcrv+R3yFDb9q2MqyqjBENJk4Q\nJn4A\r\n=riNv\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCglU3dFVBFz4HBUAtmSeOGAswCurZvfWFzdlwrU0333gIgRDSlZk8KTDy2+NsXntqwv1Dd0AojIOWKKPAVwqFBA6M="}],"size":4051,"noattachment":false,"key":"/pino-abstract-transport/-/pino-abstract-transport-0.2.0.tgz"},"directories":{},"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pino-abstract-transport_0.2.0_1621421220628_0.5721101365686796"},"_hasShrinkwrap":false,"readme":"# pino-abstract-transport\n[![npm version](https://img.shields.io/npm/v/pino-abstract-transport)](https://www.npmjs.com/package/pino-abstract-transport)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/pinojs/pino-abstract-transport/ci.yml?branch=main)](https://github.com/pinojs/pino-abstract-transport/actions)\n[![Coverage Status](https://coveralls.io/repos/github/pinojs/pino-abstract-transport/badge.svg?branch=main)](https://coveralls.io/github/pinojs/pino-abstract-transport?branch=main)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nWrite Pino transports easily.\n\n## Install\n\n```sh\nnpm i pino-abstract-transport\n```\n\n## Usage\n\n```js\nimport build from 'pino-abstract-transport'\n\nexport default async function (opts) {\n  return build(async function (source) {\n    for await (let obj of source) {\n      console.log(obj)\n    }\n  })\n}\n```\n\nor in CommonJS and streams:\n\n```js\n'use strict'\n\nconst build = require('pino-abstract-transport')\n\nmodule.exports = function (opts) {\n  return build(function (source) {\n    source.on('data', function (obj) {\n      console.log(obj)\n    })\n  })\n}\n```\n\n## Typescript usage\n\nInstall the type definitions for node. Make sure the major version of the type definitions matches the node version you are using.\n\n#### Node 16\n\n```sh\nnpm i -D @types/node@16\n```\n\n## API\n\n### build(fn, opts) => Stream\n\nCreate a [`split2`](http://npm.im/split2) instance and returns it.\nThis same instance is also passed to the given function, which is called\nsynchronously.\n\nIf `opts.transform` is `true`, `pino-abstract-transform` will \nwrap the split2 instance and the returned stream using [`duplexify`](https://www.npmjs.com/package/duplexify),\nso they can be concatenated into multiple transports.\n\n#### Events emitted\n\nIn addition to all events emitted by a [`Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)\nstream, it emits the following events:\n\n* `unknown` where an unparsable line is found, both the line and optional error is emitted.\n\n#### Options\n\n* `parse` an option to change to data format passed to build function. When this option is set to `lines`,\n  the data is passed as a string, otherwise the data is passed as an object. Default: `undefined`.\n\n* `close(err, cb)` a function that is called to shutdown the transport. It's called both on error and non-error shutdowns.\n  It can also return a promise. In this case discard the the `cb` argument.\n\n* `parseLine(line)` a function that is used to parse line received from `pino`.\n\n* `expectPinoConfig` a boolean that indicates if the transport expects Pino to add some of its configuration to the stream. Default: `false`.\n\n## Example\n\n### custom parseLine\n\nYou can allow custom `parseLine` from users while providing a simple and safe default parseLine.\n\n```js\n'use strict'\n\nconst build = require('pino-abstract-transport')\n\nfunction defaultParseLine (line) {\n  const obj = JSON.parse(line)\n  // property foo will be added on each line\n  obj.foo = 'bar'\n  return obj\n}\n\nmodule.exports = function (opts) {\n  const parseLine = typeof opts.parseLine === 'function' ? opts.parseLine : defaultParseLine\n  return build(function (source) {\n    source.on('data', function (obj) {\n      console.log(obj)\n    })\n  }, {\n    parseLine: parseLine\n  })\n}\n```\n\n### Stream concatenation / pipeline\n\nYou can pipeline multiple transports:\n\n```js\nconst build = require('pino-abstract-transport')\nconst { Transform, pipeline } = require('stream')\n\nfunction buildTransform () {\n  return build(function (source) {\n    return new Transform({\n      objectMode: true,\n      autoDestroy: true,\n      transform (line, enc, cb) {\n        line.service = 'bob'\n        cb(null, JSON.stringify(line))\n      }\n    })\n  }, { enablePipelining: true })\n}\n\nfunction buildDestination () {\n  return build(function (source) {\n    source.on('data', function (obj) {\n      console.log(obj)\n    })\n  })\n}\n\npipeline(process.stdin, buildTransform(), buildDestination(), function (err) {\n  console.log('pipeline completed!', err)\n})\n```\n\n### Using pino config\n\nSetting `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.\n\nWhen used with an incompatible version of pino, the stream will immediately error.\n\n```js\nimport build from 'pino-abstract-transport'\n\nexport default function (opts) {\n  return build(async function (source) {\n    for await (const obj of source) {\n      console.log(`[${source.levels.labels[obj.level]}]: ${obj[source.messageKey]}`)\n    }\n  }, {\n    expectPinoConfig: true\n  })\n}\n```\n\n## License\n\nMIT\n","publish_time":1621421220809,"_cnpm_publish_time":1621421220809,"dist-tags":{"latest":"3.0.0"}}