pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.21k stars 875 forks source link

Is it possible to pipe to a transport and not to stdout #461

Closed danielo515 closed 6 years ago

danielo515 commented 6 years ago

Hello, I'm very new to pino and I didn't find any link to community so I'm asking here, sorry if it is not correct.

I am used to loggers where you can specify the log level (usually by env variables, but that is not a problem to me) but that only means "what is sent to stdout". So, for performance reasons, logs are not shown on console, but if there is any transport configured they are sent to that transport, so you can lookup on your log aggregator for them. Since pino uses unix pipes to handle log transport, if something is not sent to stdout it is not sent to any transport. Is there any way to achieve what I'm describing ?

davidmarkclements commented 6 years ago

hey @danielo515 take a look at how we do transports here: https://github.com/pinojs/pino/blob/master/docs/transports.md

Then check out https://github.com/pinojs/pino-tee

Closing for now but feel free to follow up

danielo515 commented 6 years ago

Hello @davidmarkclements , Thanks for pointing me to pine-tee. At the end I didn't used it, but one of the stream examples helped me to build a solution to my another problem.

My problem was that I was using a shell specific for micro-services (fuge). It has many great features, but log processing is not one of them, and it does not accept an option to provide a log processor. So my solution was to use a special node script to execute all the services. This node service is the responsible of running the process and piping the output to pino.pretty. Is as simple as this:

const pino = require ('pino');
const { spawn } = require ('child_process');
const { join } = require ('path');

const child = spawn (process.execPath,
    [ join (
                process.cwd (), 'index.js'
               )
    ]);

const pretty = pino.pretty ();
pretty.pipe (process.stdout);
child.stdout.pipe (pretty);

Then I just run my script instead of the actual index.js file. Now I just have to explore the pretty options to make it even prettier. Now I have pretty logs on develop and concise and performant logs on production, where I'm using gelf logging driver of docker, which was surprisingly easy to setup.

Regards

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.