pinojs / pino

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

How do you preserve color output from other commands? #408

Closed pajtai closed 6 years ago

pajtai commented 6 years ago

Greater logger! I have a question:

I'm piping to the pino cli to parse and colorize Pino logs, but I sometimes have other output that comes with colors, and the pino cli removes these colors.

For example, I use eslint - which has colored output - how can I preserve that?

Example command nodemon index.js --exec 'npm run lint && node' | pino

davidmarkclements commented 6 years ago

By the time it reaches the prettifier (pino) there is no color.

Try the following: nodemon index.js --exec 'npm run lint && node' | cat

You should see that there's no color, because generally CLI tools that output color will check process.stdout.isTTY (or require('tty').isatty()) and then output the additional terminal codes (or not).

node -p process.stdout.isTTY -> true node -p process.stdout.isTTY | cat -> undefined

davidmarkclements commented 6 years ago

Closing for now, but if you want to keep color through a pipe that's down to configuring which ever libs are outputting colour (if they have that option)

pajtai commented 6 years ago

@davidmarkclements Thanks for that info.

And sure enough, eslint has a --color option that forces color even if isTTY is falsey.

I'll add my config here to preserve eslint colors through a pipe for anyone else who might find it helpful:

  "scripts": {
    "dev": "nodemon index.js --exec 'npm run lint && node' | pino",
    "lint": "eslint --color ."
  },
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.