Skip to content
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

Colorize with uppercase level creates lots of blank lines before log message #1345

Closed
kingjerod opened this issue May 31, 2018 · 4 comments · Fixed by winstonjs/logform#34
Closed
Labels
Feature Request Request for new functionality to support use cases not already covered

Comments

@kingjerod
Copy link

kingjerod commented May 31, 2018

Please tell us about your environment:

  • winston version?_
    • winston@2
    • [-] winston@3.0.0-rc6
  • node -v outputs: v10.1.0
  • Operating System: Linux (Official Docker image)
  • Language: TypeScript 2.6.2

What is the problem?

Using a custom format that uppercases the level with colorize will cause the log line output to have lots of empty space before it (clears my console so probably 50+ empty lines).

What do you expect to happen instead?

Ideally the upper cased level would be colorized. Worst case is it would not be colorized.

Other information

Here is the code:

const custom = format.printf((info) => {
  return `${info.level.toUpperCase()}: ${info.message}`;
});

const log = createLogger({
  format: format.combine(
    format.colorize(),
    custom
  ),
  transports: [new transports.Console()]
});

It works fine if I do .toLowerCase()

@indexzero
Copy link
Member

info.level is mutable. It is changed from 'error' or 'info' to a string that includes ANSI color codes. e.g.:

// level = '\u001b[32minfo\u001b[39m'
info: wut
// level = '\u001b[32minfo\u001b[39m'
info: ok
// level = '\u001b[31merror\u001b[39m'
error: sure

... not 100% the right approach to add this feature. The underlying colorize code is in logform

@indexzero indexzero added the Feature Request Request for new functionality to support use cases not already covered label May 31, 2018
@indexzero
Copy link
Member

indexzero commented Jun 1, 2018

@kingjerod this should be fixed by winstonjs/logform#34. Once that lands you can solve this by:

const custom = format.printf((info) => {
  return `${info.level}: ${info.message}`;
});

const log = createLogger({
  format: format.combine(
    format(info => {
      info.level = info.level.toUpperCase()
      return info;
    })(),
    format.colorize(),
    custom
  ),
  transports: [new transports.Console()]
});

@Baptiste-Garcin
Copy link

I still have this bug with wintston@3.4.0 shipped with logform@2.3.2 (this tag has been push 2 days ago).

Do I miss something ?

@kmordan24
Copy link

kmordan24 commented Jan 31, 2022

@Baptiste-Garcin
It could just be you still have the level.toUppercase() if you use printf. I added the format in this reply above and it still didn't work only for me to realize I still had the other toUppercase. For example:

const LOG_FORMAT = winston.format.printf(
  (info) =>
    `${info.timestamp} ${info.level/*NO TO UPPERCASE*/}${info.label ? ` [${info.label}]` : ''}: ${info.message}`
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Request for new functionality to support use cases not already covered
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants