From 38586b936fed8f8cb189427e8eef929cccefbc4e Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 16 Mar 2016 11:42:18 +0100 Subject: [PATCH 1/2] Explain why there are no transports. Fixed #9. --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index c1181789d..eab16076c 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ It also includes a shell utility to pretty-print its log files. * [Benchmarks](#benchmarks) * [API](#api) * [How do I rotate log files?](#rotate) +* [What happened to my transports?](#transports) * [Acknowledgements](#acknowledgements) * [License](#license) @@ -299,6 +300,28 @@ In order to rotate your log files, add in `/etc/logrotate.d/myapp`: } ``` + +## What happened to my transports? + +There will never be an API for transports, or support for ObjectMode Writable streams. +This library is fast because it does way less than the others. We went a +great length to make sure this library is _really fast_, and transports +will slow things down. + +So, how do you do a transport? You create another node process to do that, and you pipe them together. +It's the Unix philosophy. + +Something like: + +```js +var split = require('split2') +var pump = require('pump') + +pump(process.stdin, split2(JSON.parse), myAwesomeTransport) +``` + +Doing it inside the same process will add unnecessary load to your single-threaded node.js, effectively slowing you down. + ## Acknowledgements From df1ebabfe10fa9a4f77eb9ef8f88655822a4b544 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 16 Mar 2016 12:07:28 +0100 Subject: [PATCH 2/2] Corrections from @davidmarkclements and @danjenkins --- README.md | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index eab16076c..00335d0a7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ It also includes a shell utility to pretty-print its log files. * [Benchmarks](#benchmarks) * [API](#api) * [How do I rotate log files?](#rotate) -* [What happened to my transports?](#transports) +* [How to use Transports with Pino](#transports) * [Acknowledgements](#acknowledgements) * [License](#license) @@ -301,14 +301,15 @@ In order to rotate your log files, add in `/etc/logrotate.d/myapp`: ``` -## What happened to my transports? +## How to use Transports with Pino -There will never be an API for transports, or support for ObjectMode Writable streams. -This library is fast because it does way less than the others. We went a -great length to make sure this library is _really fast_, and transports +Transports are not part of Pino. There will never be an API for transports, +or support for ObjectMode Writable streams. +This library is fast because it does way less than the others. We went +to great lengths to make sure this library is _really fast_, and transports will slow things down. -So, how do you do a transport? You create another node process to do that, and you pipe them together. +So, how do you do a transport? With Pino, we create a separate process for our transport and pipe to it. It's the Unix philosophy. Something like: @@ -316,11 +317,20 @@ Something like: ```js var split = require('split2') var pump = require('pump') +var through = require('through2') -pump(process.stdin, split2(JSON.parse), myAwesomeTransport) +var myTransport = through.obj(function (chunk, enc, cb) { + // do whatever you want here! + console.log(chunk) + cb() +} + +pump(process.stdin, split2(JSON.parse), myTransport) ``` -Doing it inside the same process will add unnecessary load to your single-threaded node.js, effectively slowing you down. +Using transports in the same process causes unnecessary load and slows down Node's single threaded event loop. + +If you write a transport, let us know and we will add a link here! ## Acknowledgements