pino-pretty icon indicating copy to clipboard operation
pino-pretty copied to clipboard

Option to replace the default colors used.

Open dmarvp opened this issue 4 years ago • 8 comments

I want to set the colorized version of a message to something other than cyan. Is there an easy way to do this?

dmarvp avatar Jun 24 '20 21:06 dmarvp

Not at the moment. If you’d like to submit a PR to make it possible, that’d be great.

jsumners avatar Jun 24 '20 21:06 jsumners

cyan sucks, especially when you've got special background on your terminal

celesteking avatar Sep 22 '20 18:09 celesteking

cyan sucks, especially when you've got special background on your terminal

Such comments are not helpful or constructive. You have the power to effect the change you want to see.

jsumners avatar Sep 22 '20 21:09 jsumners

@dmarvp A bit late but was wondering how to change the message color as well.

Here's what I do to have message in white:

const logger = pino({
	level: "debug",
	prettyPrint: {
		colorize: true,
		ignore: "hostname,pid,time",
		messageFormat: "{levelLabel} \x1B[37m{msg}"
	}
});

Copdate-Copdate avatar Dec 27 '20 02:12 Copdate-Copdate

@Copdate-Copdate You can do that be sending in a PR :D

kibertoad avatar Jul 16 '21 15:07 kibertoad

b

illia-lab avatar Aug 31 '23 16:08 illia-lab

{
  customColors: 'message:whiteBright'
}

vladshcherbin avatar Oct 19 '23 12:10 vladshcherbin

Here is my solution. Hope it helps. I wanted the message and level to match colors. You can modify my code with the escape codes here: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797

const stream = pretty({
  colorize: true,
  customColors: {
    trace: "cyan",
    debug: "blue",
    info: "reset",
    warn: "yellow",
    error: "red",
    fatal: "red",
  },
  messageFormat: (log, messageKey, levelLabel) => {
    const trace = `\u001b[36m${log.msg}\u001b[0m`; // Cyan text
    const debug = `\u001b[34m${log.msg}\u001b[0m`; // Blue text
    const info = `\u001b[39m${log.msg}\u001b[0m`; // Default text
    const warn = `\u001b[33m${log.msg}\u001b[0m`; // Yellow text
    const error = `\u001b[31m${log.msg}\u001b[0m`; // Red text
    const fatal = `\u001b[41m\u001b[37m${log.msg}\u001b[0m`; // Red background with white text
    if (typeof log.level === "string") {
      switch (log.level) {
        case "trace":
          return trace;
        case "debug":
          return debug;
        case "info":
          return info;
        case "warn":
          return warn;
        case "error":
          return error;
        case "fatal":
          return fatal;
        default:
          return log.msg;
      }
    } else {
      switch (log.level) {
        case 10:
          return trace;
        case 20:
          return debug;
        case 30:
          return info;
        case 40:
          return warn;
        case 50:
          return error;
        case 60:
          return fatal;
        default:
          return log.msg;
      }
    }
  }
});

kindagonzo avatar Jan 19 '24 14:01 kindagonzo