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

disableRequestLogging should disable logs in default error handler #5409

Closed
2 tasks done
SamSalvatico opened this issue Apr 19, 2024 · 6 comments · Fixed by #5435
Closed
2 tasks done

disableRequestLogging should disable logs in default error handler #5409

SamSalvatico opened this issue Apr 19, 2024 · 6 comments · Fixed by #5435
Labels
feature request New feature to be added good first issue Good for newcomers

Comments

@SamSalvatico
Copy link
Contributor

SamSalvatico commented Apr 19, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.26.2

Plugin version

No response

Node.js version

v20.11.1

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.4.1

Description

I am trying to have a full control over the log entries Fastify writes and I noticed that in the default error handler it writes records without checking the disableRequestLogging value.

Should it check if and disable logging when it is true or is it preferred to set a custom error handler to prevent it?

Steps to Reproduce

import fastify from 'fastify';

const server = fastify({
    disableRequestLogging: true
});

server.get('/ping', async (request, reply) => {
    throw new Error('err');
})

server.listen({ port: 8080 }, (err, address) => {
    if (err) {
        process.exit(1)
    }
})

Expected Behavior

No log entries added when an error is managed by the default error handler

@metcoder95
Copy link
Member

Setting a custom errorHandler should provide you the option to disable the logging.

Though, I do see the benefit when you might not want to customize the errorHandler but just disable the logging. Might be a good enhancement

@SamSalvatico
Copy link
Contributor Author

Setting a custom errorHandler should provide you the option to disable the logging.

Though, I do see the benefit when you might not want to customize the errorHandler but just disable the logging. Might be a good enhancement

Could I then create a PR related to this?
Thank you for you time

@metcoder95
Copy link
Member

Please, PR always welcomed

@metcoder95 metcoder95 added the feature request New feature to be added label Apr 23, 2024
@mcollina mcollina added the good first issue Good for newcomers label Apr 24, 2024
@SamSalvatico
Copy link
Contributor Author

Please, PR always welcomed

Great, I'm working on it

Would you like also to apply the same behaviour to the 404 handler?

@metcoder95
Copy link
Member

Sure, I believe the configuration should apply widely 👍

@metcoder95 metcoder95 linked a pull request May 3, 2024 that will close this issue
4 tasks
@metcoder95
Copy link
Member

Fixed through #5435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature to be added good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants