Skip to content

Commit 2dd9876

Browse files
committed
Log 404 responses at DEBUG instead of WARN to reduce log noise
1 parent 0f1ff8b commit 2dd9876

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

dspace-server-webapp/src/main/java/org/dspace/app/rest/exception/DSpaceApiExceptionControllerAdvice.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,9 @@ private void sendErrorResponseFromException(final HttpServletRequest request,
283283
if (statusCodesLoggedAsErrors.contains(statusCode)) {
284284
log.error("{} (status:{})", message, statusCode, ex);
285285
} else {
286-
// Log the error as a single-line WARN
287286
StackTraceElement[] trace = ex.getStackTrace();
288287
String location = trace.length <= 0 ? "unknown" : trace[0].toString();
289-
log.warn("{} (status:{} exception: {} at: {})",
290-
message, statusCode, ex.getClass().getName(), location);
288+
logClientError(statusCode, message, ex.getClass().getName(), location);
291289
}
292290

293291
response.sendError(statusCode, message);
@@ -322,7 +320,6 @@ private void sendErrorResponse(final HttpServletRequest request,
322320
// Log the full error and status code
323321
log.error("{} (status:{})", message, statusCode, ex);
324322
} else if (HttpStatus.valueOf(statusCode).is4xxClientError()) {
325-
// Log the error as a single-line WARN
326323
String location;
327324
String exceptionMessage;
328325
if (null == ex) {
@@ -333,14 +330,27 @@ private void sendErrorResponse(final HttpServletRequest request,
333330
StackTraceElement[] trace = ex.getStackTrace();
334331
location = trace.length <= 0 ? "unknown" : trace[0].toString();
335332
}
336-
log.warn("{} (status:{} exception: {} at: {})", message, statusCode,
337-
exceptionMessage, location);
333+
logClientError(statusCode, message, exceptionMessage, location);
338334
}
339335

340336
//Exception properties will be set by org.springframework.boot.web.support.ErrorPageFilter
341337
response.sendError(statusCode, message);
342338
}
343339

340+
/**
341+
* Log a 4xx client error. 404 NOT_FOUND is logged at DEBUG level (normal REST response),
342+
* all other 4xx errors are logged at WARN level.
343+
*/
344+
private void logClientError(int statusCode, String message, String exceptionMessage, String location) {
345+
if (statusCode == HttpServletResponse.SC_NOT_FOUND) {
346+
log.debug("{} (status:{} exception: {} at: {})", message, statusCode,
347+
exceptionMessage, location);
348+
} else {
349+
log.warn("{} (status:{} exception: {} at: {})", message, statusCode,
350+
exceptionMessage, location);
351+
}
352+
}
353+
344354
/**
345355
* Get set of status codes that should be treated as errors.
346356
*

0 commit comments

Comments
 (0)