From 795c933f5093b43638ba41dcc22548e41af0e510 Mon Sep 17 00:00:00 2001 From: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Date: Fri, 13 Mar 2026 15:00:08 +0100 Subject: [PATCH 1/2] Reduce warn logs noise (#1268) * Log 404 responses at DEBUG instead of WARN to reduce log noise * Log 404 responses at DEBUG instead of WARN (configurable via logging.server.debug-404) * Skip stack trace extraction for suppressed 404 debug logs * Replace custom debug-404 property with dedicated Log4j2 logger (org.dspace.app.rest.NotFound) * Suppress 404 warn logs via dedicated Log4j2 logger (org.dspace.app.rest.NotFound) * Turn off that warn logs for the dspace.log * Updated log name to be more unique --- .../DSpaceApiExceptionControllerAdvice.java | 31 ++++++++++++++----- dspace/config/log4j2.xml | 7 +++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java index 4833cb938317..7faf82f379f4 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java @@ -61,6 +61,13 @@ public class DSpaceApiExceptionControllerAdvice extends ResponseEntityExceptionHandler { private static final Logger log = LogManager.getLogger(); + /** + * Dedicated logger for 404 NOT_FOUND responses. Configured at OFF level by default + * so that expected 404s don't flood production logs. + * Set to WARN in log4j2.xml to see 404 responses in logs. + */ + private static final Logger notFoundLog = LogManager.getLogger("org.dspace.app.rest.exception.DSpaceApiExceptionControllerAdvice.NotFound"); + /** * Default collection of HTTP error codes to log as ERROR with full stack trace. */ @@ -283,11 +290,9 @@ private void sendErrorResponseFromException(final HttpServletRequest request, if (statusCodesLoggedAsErrors.contains(statusCode)) { log.error("{} (status:{})", message, statusCode, ex); } else { - // Log the error as a single-line WARN StackTraceElement[] trace = ex.getStackTrace(); String location = trace.length <= 0 ? "unknown" : trace[0].toString(); - log.warn("{} (status:{} exception: {} at: {})", - message, statusCode, ex.getClass().getName(), location); + logClientError(statusCode, message, ex.getClass().getName(), location); } response.sendError(statusCode, message); @@ -322,7 +327,6 @@ private void sendErrorResponse(final HttpServletRequest request, // Log the full error and status code log.error("{} (status:{})", message, statusCode, ex); } else if (HttpStatus.valueOf(statusCode).is4xxClientError()) { - // Log the error as a single-line WARN String location; String exceptionMessage; if (null == ex) { @@ -333,14 +337,28 @@ private void sendErrorResponse(final HttpServletRequest request, StackTraceElement[] trace = ex.getStackTrace(); location = trace.length <= 0 ? "unknown" : trace[0].toString(); } - log.warn("{} (status:{} exception: {} at: {})", message, statusCode, - exceptionMessage, location); + logClientError(statusCode, message, exceptionMessage, location); } //Exception properties will be set by org.springframework.boot.web.support.ErrorPageFilter response.sendError(statusCode, message); } + /** + * Log a 4xx client error. 404 NOT_FOUND is sent to a dedicated logger ({@link #notFoundLog}) + * at WARN level, but the logger is set to OFF by default in log4j2.xml (suppressed). + * Set logger to WARN in log4j2.xml to see 404 responses in logs. + */ + private void logClientError(int statusCode, String message, String exceptionMessage, String location) { + if (statusCode == HttpServletResponse.SC_NOT_FOUND) { + notFoundLog.warn("{} (status:{} exception: {} at: {})", message, statusCode, + exceptionMessage, location); + } else { + log.warn("{} (status:{} exception: {} at: {})", message, statusCode, + exceptionMessage, location); + } + } + /** * Get set of status codes that should be treated as errors. * @@ -355,7 +373,6 @@ private Set getStatusCodesLoggedAsErrors() { statusCodesLoggedAsErrors.add(Integer.valueOf(code)); } catch (NumberFormatException e) { log.warn("Non-integer HTTP status code {} in {}", code, P_LOG_AS_ERROR); - // And continue } } return statusCodesLoggedAsErrors; diff --git a/dspace/config/log4j2.xml b/dspace/config/log4j2.xml index 3273551bc0f6..a2ad06ee33a6 100644 --- a/dspace/config/log4j2.xml +++ b/dspace/config/log4j2.xml @@ -89,6 +89,13 @@ + + + + + Date: Fri, 13 Mar 2026 15:24:27 +0100 Subject: [PATCH 2/2] The row lenght was updated to be less than 120 chars (#1274) --- .../app/rest/exception/DSpaceApiExceptionControllerAdvice.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java index 7faf82f379f4..ce05086ab96b 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java @@ -66,7 +66,8 @@ public class DSpaceApiExceptionControllerAdvice extends ResponseEntityExceptionH * so that expected 404s don't flood production logs. * Set to WARN in log4j2.xml to see 404 responses in logs. */ - private static final Logger notFoundLog = LogManager.getLogger("org.dspace.app.rest.exception.DSpaceApiExceptionControllerAdvice.NotFound"); + private static final Logger notFoundLog = + LogManager.getLogger("org.dspace.app.rest.exception.DSpaceApiExceptionControllerAdvice.NotFound"); /** * Default collection of HTTP error codes to log as ERROR with full stack trace.