pino-pretty
pino-pretty copied to clipboard
Option to replace the default colors used.
I want to set the colorized version of a message to something other than cyan. Is there an easy way to do this?
Not at the moment. If you’d like to submit a PR to make it possible, that’d be great.
cyan sucks, especially when you've got special background on your terminal
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.
@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 You can do that be sending in a PR :D
b
{
customColors: 'message:whiteBright'
}
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;
}
}
}
});