Closed NotLazy closed 10 months ago
log.hooks.push((msg, _, transportName) => {
if (transportName === 'console') {
msg.data.unshift('color: blue', 'color: unset');
}
return msg;
});
log.hooks.push((msg, _, transportName) => { if (transportName === 'console') { msg.data.unshift('color: blue', 'color: unset'); } return msg; });
This works for console but causes file and remote handlers to have this text in them, even though specifically locking it with transportName
in the log file:
[2024-02-05 22:09:11.408] [info] (main) color: cyan color: unset App is ready and has been initialized
[2024-02-05 22:09:11.998] [info] (app) color: cyan color: unset Loading 15
[2024-02-05 22:09:12.145] [info] (app) color: cyan color: unset Loading 17
[2024-02-05 22:09:12.961] [info] (app) color: cyan color: unset loaded
[2024-02-05 22:09:12.967] [info] (app) color: cyan color: unset loaded
Ok, try clonning msg object instead
log.hooks.push((msg, _, transportName) => {
if (transportName === 'console') {
return {
...msg,
data: ['color: blue', 'color: unset', ...msg.data],
}
}
return msg;
});
Ok, try clonning msg object instead
This worked. I had tried only cloning msg or only cloning msg.data but, cloning both was the answer here. Thanks!
When I use the default console transport format, I get color and my logged messages:
But when I use a custom console transport format:
Here's my custom format:
%c{h}:{i}:{s}.{ms}%c {sender} › {text}
sender is defined usinglog.variables.sender = currentContext;
before calling log.silly() or log.info() (the two levels shown in screenshots)