wrong chars inside .log file `` and `[39m` when using colorize()

See original GitHub issue
  • winston 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  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:

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

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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
Ks89commented, Jul 23, 2018

Fixed using colorize ONLY inside transports.Console, instead of globally. I don’t know why but it’s working.

...
if (process.env.NODE_ENV !== 'production') {
    logger.add(new transports.Console({
        ...
        format: format.combine(
            format.colorize({
                all: true
            }),
           ...
        ),
    }));
}
2reactions
DABHcommented, Jul 22, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found