I'm trying to make my own Winston logger implementation with similar color pattern to NestJS's ones, but I'm not being successful.
I'm not able to colorize words in the middle of the log nor to add the ms at the end. This is my current implementation:
format: winston.format.combine(
winston.format.colorize({ all: true }),
winston.format.timestamp({ format: 'DD-MM-YYYY, HH:mm:ss' }),
winston.format.align(),
winston.format.json(),
winston.format.errors({ stack: true }),
winston.format.printf(({ message, timestamp }) => {
const logTraceId = this.traceId ? `[${this.traceId}]` : '';
const logContext = this.context ? `[${this.context}]` : '';
return `${timestamp} - ${logContext}${logTraceId} ${message}`;
}),
winston.format.ms(),
),
I would like to, for instance, make RoutesResolver
in yellow in the middle of the log. Same for traceId. Also adding the ms at the end of the logs.
Could someone enlighten me here? Thank you all!
Ok, this can be achievable by using Chalk or Ogma Styler. With both, we are able to colorize any string that will be prompted in the console, and here is the result: