-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
I can not colorize only the console logger #1384
Comments
sandrocsimas
changed the title
Cannot colorize only console logger
Can not colorize only console logger
Jun 28, 2018
sandrocsimas
changed the title
Can not colorize only console logger
I can not colorize only the console logger
Jun 28, 2018
The formats are applied in order meaning the logger formats are applied first, then the transport formats are applied. The following example would get the wanted result: const myFormat = winston.format.printf(info => `${info.timestamp} - ${info.level}: ${info.message}`);
const logger = winston.createLogger({
level: 'info',
format: winston.format.timestamp(),
transports: [
new winston.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
myFormat,
)
}),
new winston.transports.File({
filename: path.resolve('project.log'),
format: myFormat,
}),
]
}); |
To get out of the box easy colorizing in dev console with less code check out related a comment in a similar issue: #1135 (comment) |
This works for me. const colorsConfig = {
error: 'red',
warn: 'yellow',
info: 'green',
debug: 'cyan'
};
const colorizer = winston.format.colorize({ all: true, colors: colorsConfig });
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(({ level, message, timestamp, ...args }) => {
const coloredLevel = colorizer.colorize(level, `[${level.toUpperCase()}]`);
return `${timestamp} ${coloredLevel}: ${message} ${
Object.keys(args).length > 0 ? JSON.stringify(args, null, 2) : ''
}`;
})
),
...
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please tell us about your environment:
winston
version?winston@2
winston@3
node -v
outputs: v8.10.0What is the problem?
I can not colorize only the console logger.
Console output:
The console output above does not colorize the message.
What do you expect to happen instead?
I want the colorized message only in the console logger. The file should keep printing without color.
The text was updated successfully, but these errors were encountered: