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

[Bug]: forceConsole may cause circular reference if console.log is redirected to Winston #2497

Closed
neilenns opened this issue Aug 8, 2024 · 0 comments · Fixed by #2498
Closed

Comments

@neilenns
Copy link
Contributor

neilenns commented Aug 8, 2024

🔎 Search Terms

forceConsole

The problem

As mentioned in #2276 (comment), sometimes people will redirect the console.log method to a Winston logger to ensure all logged messages get captured:

console.log = logger.log.bind(logger)

Apparently, this can cause a circular reference issue, since the Winston logger will attempt to log using console.log, but that's been redirected to be the logger itself.

What version of Winston presents the issue?

v3.14.1

What version of Node are you using?

v20.11.0

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

v3.14.0

Minimum Working Example

const mainLogger = winston.createLogger({
  level: "debug",
  transports: [
    new winston.transports.Console({ forceConsole: true }),
  ],
});

console.log = mainLogger.log.bind(mainLogger);

mainLogger.log("info", "Oops");

Additional information

PR to fix this will be opened shortly.

@neilenns neilenns changed the title [Bug]: forceConsole may cause circular reference if console.log is redirected to Winston [Bug]: forceConsole may cause circular reference if console.log is redirected to Winston Aug 8, 2024
neilenns added a commit to neilenns/winston that referenced this issue Aug 8, 2024
@DABH DABH closed this as completed in #2498 Aug 8, 2024
@DABH DABH closed this as completed in e82752f Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant