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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Formatter runs on log call, even if log is not correct level #2441

Open
cerpins opened this issue Apr 5, 2024 · 0 comments
Open

[Bug]: Formatter runs on log call, even if log is not correct level #2441

cerpins opened this issue Apr 5, 2024 · 0 comments

Comments

@cerpins
Copy link

cerpins commented Apr 5, 2024

馃攷 Search Terms

Slow formatter

The problem

My application has formatters, which are slow.
When I run my application with level=info to get rid of debug logs in production, I notice that the formatter is ran for those debug logs, causing a considerable performance hit - even though level is info.

Please let me know if there is a way to work around this, or am I just misunderstanding winston and formatters. Thanks!

Here is my profiler:
image

Here is my minimal-ish reproducible:

const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.combine(
    winston.format.json(),
    winston.format((input) => {
      let lagger = 0;
      for (let i = 0; i < 1000000000; i++) {
        lagger += 1;
      }
      return input;
    })()
  ),
  defaultMeta: { service: 'user-service' },
  transports: [
    new winston.transports.Console({
      format: winston.format.simple(),
    })
  ],
});

setInterval(() => {
  // I still see formatter for this log in profiler taking up some seconds
  logger.debug('Hello world!');
}, 1000);

What version of Winston presents the issue?

v3.13.0

What version of Node are you using?

v18.18.0

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

Posted above

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant