TUL/Reduce warn logs noise - 404 dedicated logger#1279
Open
milanmajchrak wants to merge 1 commit intocustomer/TULfrom
Open
TUL/Reduce warn logs noise - 404 dedicated logger#1279milanmajchrak wants to merge 1 commit intocustomer/TULfrom
milanmajchrak wants to merge 1 commit intocustomer/TULfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces REST API log noise by routing 404 (NOT_FOUND) client errors to a dedicated Log4j2 logger that is OFF by default, while refactoring the exception handler to centralize client-error logging and status-code configuration.
Changes:
- Add a dedicated Log4j2 logger (
org.dspace.app.rest.exception.DSpaceApiExceptionControllerAdvice.NotFound) configured OFF by default. - Introduce a dedicated
notFoundLoglogger and alogClientError()helper to route 404s separately from other 4xx warnings. - Extract status-code parsing into
getStatusCodesLoggedAsErrors()and add a newsendErrorResponseFromException()helper (currently unused).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
dspace/config/log4j2.xml |
Adds an OFF-by-default logger dedicated to 404 REST responses. |
dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java |
Adds dedicated 404 logger + helper methods to reduce 404 warn noise and refactor logging/status-code handling. |
You can also share your feedback on Copilot code review. Take the survey.
| * Send the error to the response. The error message is taken from exception message. | ||
| * This method is mainly appropriate for 4xx errors, | ||
| * where the exception message should be exposed to REST API clients in response body. | ||
| * This method also logs the ERROR log, containing the first line from the exception stack trace. |
Comment on lines
261
to
297
| * Send the error to the response. The error message is taken from exception message. | ||
| * This method is mainly appropriate for 4xx errors, | ||
| * where the exception message should be exposed to REST API clients in response body. | ||
| * This method also logs the ERROR log, containing the first line from the exception stack trace. | ||
| * Specific errors where an ERROR log with full stack trace is more appropriate are configured | ||
| * using property {@code logging.server.include-stacktrace-for-httpcode} | ||
| * (see {@link DSpaceApiExceptionControllerAdvice#P_LOG_AS_ERROR} | ||
| * and {@link DSpaceApiExceptionControllerAdvice#LOG_AS_ERROR_DEFAULT}). | ||
| * | ||
| * @param request current request | ||
| * @param response current response | ||
| * @param ex Exception causing the error response | ||
| * @param statusCode status code to send in response | ||
| */ | ||
| private void sendErrorResponseFromException(final HttpServletRequest request, | ||
| final HttpServletResponse response, | ||
| final Exception ex, | ||
| final int statusCode) | ||
| throws IOException { | ||
| //Make sure Spring picks up this exception | ||
| request.setAttribute(EXCEPTION_ATTRIBUTE, ex); | ||
|
|
||
| final Set<Integer> statusCodesLoggedAsErrors = getStatusCodesLoggedAsErrors(); | ||
|
|
||
| String message = ex.getMessage(); | ||
| if (statusCodesLoggedAsErrors.contains(statusCode)) { | ||
| log.error("{} (status:{})", message, statusCode, ex); | ||
| } else { | ||
| StackTraceElement[] trace = ex.getStackTrace(); | ||
| String location = trace.length <= 0 ? "unknown" : trace[0].toString(); | ||
| logClientError(statusCode, message, ex.getClass().getName(), location); | ||
| } | ||
|
|
||
| response.sendError(statusCode, message); | ||
| } | ||
|
|
||
| /** |
Comment on lines
+365
to
+367
| String[] error_codes = configurationService.getArrayProperty( | ||
| P_LOG_AS_ERROR, LOG_AS_ERROR_DEFAULT); | ||
| for (String code : error_codes) { |
d2b67c3 to
172cc68
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick of commits 1dc5339 and db67645 into customer/TUL.
Problem description
Original commits: