-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Colourized timestamp #112
Comments
This is already possible and I am using it in development. You need to install chalk. Then you can do: const chalk = require('chalk');
const { combine, timestamp, colorize, align, printf } = winston.format;
new winston.transports.Console({
format: combine(
timestamp(),
colorize(),
align(),
printf(
({ timestamp, level, message }) => chalk`[{keyword('lightblue') ${timestamp}}] ${level}: ${message}`
)
)
}); See chalk's documentation on tagged template literals https://github.com/chalk/chalk#tagged-template-literal In case you're curious, this is what i'm using currently: if (process.env.NODE_ENV !== 'production') {
logger.add(new transports.Console({
format: combine(
format.splat(),
format.colorize(),
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
format.ms(),
printf(({ timestamp, level, message, ms }) => {
return chalk`[{keyword('lightblue') ${timestamp}}] [${level}]: ${message} {keyword('magenta') ${ms}}`
})
)
}));
} |
This is already possible with the winston-timestamp-colorize module, as the name says it allows you to colorize the timestamp. Example: const winston = require("winston");
const timestampColorize = require("winston-timestamp-colorize");
const logger = winston.createLogger({
format: winston.format.combine(
winston.format.splat(),
winston.format.align(),
winston.format.timestamp(),
winston.format.colorize(),
timestampColorize({ color: "red" }),
winston.format.printf(
info => `${info.timestamp} [${info.level}]:${info.message}`
)
),
level: "debug",
transports: [new winston.transports.Console({})]
});
logger.debug("Hello world!"); Available colors are:
|
I'm currently using a format like so:
I wanted to set a colour to my timestamp, I don't see a way of doing that at this point. Adding this to the
colors
object would be ideal. Something like:I have a small recommendation for the default color for timestamp too:
#666666
, in case anyone's listening :)The text was updated successfully, but these errors were encountered: