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

Decrease log level for 4xx HTTP errors : alternative option #1304

Merged

Conversation

ccoVeille
Copy link
Contributor

Pull Request Template

Description:

This PR is an alternative implementation of what was initiated with

It goes further than #1298 as it allows defining the log level for any error, not only the HTTP errors

It also provides a way for user to provide a log level for their custom errors (See docs/advanced-guide/gofr-errors/page.md)

Fixes #1279
Replaces #1295
Replaces #1298

Checklist:

  • I have formatted my code using goimport and golangci-lint.
  • All new code is covered by unit tests.
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

@ccoVeille ccoVeille changed the title Fix/4xx logs alternative option Decrease log level for 4xx HTTP errors : alternative option Dec 13, 2024
@ccoVeille
Copy link
Contributor Author

Can someone tell me why the tests are failing ?

I think it's about port already in use, so it could be related to:

Copy link
Contributor

@Umang01-hash Umang01-hash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed adding the LogLevel() method to the errors of the http package. Without that all the http errors will be printed at ERROR level.

Copy link
Member

@aryanmehrotra aryanmehrotra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am doubtful and not convinced.
Right now, all the errors are logged at error level, will it be really beneficial from the user perspective to write a method to set the log level for their errors.

Because errors should be logged at error levels or based on the status code.

I.E 4xx being logged at INFO

@vipul-rawat
Copy link
Member

In my opinion, since all 4xx logs are client-side errors, they are not actually errors related to the server and should be logged at the INFO level like 2xx logs. Just 5xx logs should be considered errors for the server as they are unexpected and server-side errors.

@ccoVeille
Copy link
Contributor Author

I think you missed adding the LogLevel() method to the errors of the http package. Without that all the http errors will be printed at ERROR level.

Indeed, I might have forgotten to commit a local file 🤦‍♂️😅

I will take a look.

@ccoVeille
Copy link
Contributor Author

In my opinion, since all 4xx logs are client-side errors, they are not actually errors related to the server and should be logged at the INFO level like 2xx logs. Just 5xx logs should be considered errors for the server as they are unexpected and server-side errors.

Exactly, having a distinct error level for http error is important.

For example 404 could be a Debug, a 403 could be a warning.

A custom error could have a need to set the log level, the same way they are allowed to have a custom status code.

But also please note the change allows providing a log level to any error in the stack

@ccoVeille ccoVeille force-pushed the fix/4xx_logs_alternative branch from 6399b33 to 2c3c779 Compare December 19, 2024 08:43
@aryanmehrotra aryanmehrotra merged commit 567a9ca into gofr-dev:development Dec 23, 2024
12 checks passed
@ccoVeille ccoVeille deleted the fix/4xx_logs_alternative branch December 23, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid Logging 4XX Status Codes as Errors
4 participants