pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.27k stars 150 forks source link

colorize json output #319

Closed sviridoff closed 2 years ago

sviridoff commented 2 years ago

I have some question, if there are a way to colorize part of output log, I tried to do the following but didnt succeed:

// logger_transport.js

import jsonColorizer from '@pinojs/json-colorizer';
import pinoPretty from 'pino-pretty';

function colorizeJSON(value) {
  return jsonColorizer(value, { pretty: true });
}

export default function (options) {
  return pinoPretty({
    ...options,
    customPrettifiers: {
      request: colorizeJSON, // trying to colorize the values of request key.
    },
  });
}

// logger.js

import pino from 'pino';

const logger = pino({
  transport: {
    target: './logger_transport',
    options: {
      colorize: true,
      translateTime: true,
      levelFirst: true,
    },
  },
});

logger.info({ request: { key: 'value' } });

Im using docker, maybe is a part of the problem, pino pretty is able to colorize the level part of the message, json colorizer not.

Im using @pinojs/json-colorizer 3.0.0, pino 7.9.0 and pino-pretty 7.5.4

sviridoff commented 2 years ago

solved following this comment https://github.com/pinojs/pino-pretty/issues/220#issuecomment-921093676 adding FORCE_COLOR to the envs