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]: Winston stops loggig after exception was handled #2462

Open
RotesBlatt opened this issue May 9, 2024 · 0 comments
Open

[Bug]: Winston stops loggig after exception was handled #2462

RotesBlatt opened this issue May 9, 2024 · 0 comments

Comments

@RotesBlatt
Copy link

RotesBlatt commented May 9, 2024

馃攷 Search Terms

handleException

The problem

After adding to a transport that it should handle an exception (with 'handleExceptions: true') and throwing an unhandled error, every log which should be logged does not get logged at all in that same transport which handled the exception. No info logging or error logging or anything in between .

What version of Winston presents the issue?

v3.13.0

What version of Node are you using?

v16.20.2

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

No response

Minimum Working Example

const consoleLogFormat = winston.format.printf((info) => {
    const date = new Date();
    return `${date.toLocaleDateString()}-${date.toLocaleTimeString()}-${info.level}: ${info.message}`;
});

const errorFileFormatter = winston.format.combine(
    winston.format.timestamp(),
    winston.format.json(),
    winston.format.errors()
);

const logger = winston.createLogger({
    level: 'info',
    exitOnError: false,
    format: winston.format.errors({
        stack: true,
    }),
    transports: [
        new winston.transports.File({
            level: 'error',
            dirname: 'logs',
            filename: 'error.log',
            format: errorFileFormatter,
            handleExceptions: true,
        }),
        new winston.transports.File({
            level: level,
            dirname: 'logs',
            filename: 'all_combined.log',
            format: consoleLogFormat,
        }),
        new winston.transports.Console({
            level: level,
            format: winston.format.combine(
                winston.format.colorize(),
                consoleLogFormat,
            )
        }),
    ],
});

In the code I throw an example error with:

const exampleFunction = () => {
throw new Error("testError");
}

Additional information

Other transports still work fine after the exception was thrown. Only the transport which handled the exception doesn't log anymore. In my case it should'nt stop logging, I want the application to continue even when an exception occurs.

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