wrong chars inside .log file `[32m` and `[39m` when using colorize()
See original GitHub issuewinston
version?-
winston@2
-
winston@3
-
node -v
outputs: v8.11.1- Operating System? (Windows, macOS, or Linux): macOS
- Language? (all | TypeScript X.X | ES6/7 | ES5 | Dart): ES6
What is the problem?
When I add colorize(), my .log file contains [32m
and [39m
.
Why is it happening?
This is my code:
'use strict';
const { format, createLogger, transports } = require('winston');
const logger = createLogger({
format: format.combine(
format.colorize({ all: true }),
format.simple()
),
transports: [
new transports.File({ filename: 'combined.log' }),
new transports.Console({ handleExceptions: true })
]
});
logger.info('Hello there. How are you?');
logger.info('Hello again distributed logs', {
pippo: {
pluto: 'cio',
ooo: 2.4,
sasas: [1, 2, 3],
ole: {
prova: true
}
}
});
logger.warn('some foobar level-ed message');
logger.error('some baz level-ed message');
logger.silly('some bar level-ed message');
This is the result log:
[32minfo[39m: [32mHello there. How are you?[39m
[32minfo[39m: [32mHello again distributed logs[39m {"pippo":{"pluto":"cio","ooo":2.4,"sasas":[1,2,3],"ole":{"prova":true}}}
[33mwarn[39m: [33msome foobar level-ed message[39m
[31merror[39m: [31msome baz level-ed message[39m
Removing this line from my code: format.colorize({ all: true })
My log file become correct:
info: Hello there. How are you?
info: Hello again distributed logs {"pippo":{"pluto":"cio","ooo":2.4,"sasas":[1,2,3],"ole":{"prova":true}}}
warn: some foobar level-ed message
error: some baz level-ed message
What do you expect to happen instead?
Log file shouldn’t contains [32m and [39m
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed using colorize ONLY inside transports.Console, instead of globally. I don’t know why but it’s working.
Strange! I think those chars are supposed to be what set the colors, not quotes. Do you know if you’ve done anything special regarding your terminal environment (is this stock os x terminal, some IDE, etc.), any custom settings? Could be an issue with colorize, not totally sure at first glance.