-
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
Console logging is not colorized. #1135
Comments
I was able to get it partially working using the documentation for logform.
Not sure how to handle dumping the JSON arguments. Update here is what I worked out:
|
After two hours I managed to get the colors working, thanks @xeoncross ! |
started winston and also got console without colors...
after reading this thread i did like this:
and got no difference.
|
Thanks @abrakadobr ! that did the trick. |
nothing here worked for me, still no colors, and shifting colorize to the top caused the info field to log encoded strings |
I created a gist that shows how to use winston & morgan logging in a simple expressjs app. |
Thanks @xeoncross! Adding winston.format.colorize() to my format worked. Interesting that this isn't in the docs. Or at least I couldn't find it in the docs. |
I love the new flexibility, but I hope it gets better documentation. I just spent too long getting this to work. A plug-n-play example for those of us who were using |
Anyone know how to do it with the current release version? A release candidate version is not an option. |
In reading the code you can also send
|
@markhealey I already removed winston dependency from my package.json and then I read your message. Thank you 👍 |
Thx @xeoncross. Take a look at: https://github.com/winstonjs/logform/blob/master/timestamp.js. You can format timestamp with
|
const colorizer = winston.format.colorize();
const logger = winston.createLogger({
level: 'debug',
format: combine(
winston.format.timestamp(),
winston.format.simple(),
winston.format.printf(msg =>
colorizer.colorize(msg.level, `${msg.timestamp} - ${msg.level}: ${msg.message}`)
)
),
transports: [
new transports.Console(),
]
}); |
check my full featured logger |
Thanks @abrakadobr, your solution worked for me. |
@tommuhm I see the defect now. There isn't a built-in format option for const { createLogger, format, transports } = require('../');
const logger = createLogger({
level: 'debug',
format: format.combine(
format.timestamp(),
format.simple(),
format.printf(info => `${info.timestamp} - ${info.level}: ${info.message}`),
format.colorize({ all: true })
),
transports: [
new transports.Console(),
]
});
logger.error('wowza'); The tricky bit is having the |
@xeoncross we can also achieve the same in a much simpler way const { createLogger, format, transports } = require('winston');
const { combine, timestamp, colorize, printf } = format;
const level = process.env.LOG_LEVEL || 'debug';
const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} ${level}: ${message}`;
});
const logger = createLogger({
format: combine(colorize(), timestamp(), myFormat),
transports: [new transports.Console()]
}); reference: https://www.npmjs.com/package/winston#using-custom-logging-levels |
i am using winston for logging in cloudwatch and trying to add color but instead of color symbols appear.. I try all solutions mention above. below is my code
and in cloudwatch console output is
this [39m apear instead of color. Any suggestion? |
I'm having the same issue as well. Did you manage to fix it? |
Any updates on that? Did you solve it somehow? |
That did the trick for me in iTerm on MacOS |
Below link has worked for me: |
Reading this in 2023? The solution here didn't work for me. This is how I could get it to work. 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) : ''
}`;
})
),
...
}); |
I have a very customized logger and placing the colorized statement at the end of the format was what worked for me. Thank u.
|
I'm trying to colorize the console output and it's not working. The output is all the same (white) color. I'm on 3.0.0-rc1.
I also tried the suggestion here but that's not working either:
logger.add(new winston.transports.Console({format: winston.format.combine(formatter, winston.format.colorize())}));
Thanks,
Alvaro
The text was updated successfully, but these errors were encountered: