From f3cc34d765fd93b0500aabf770bc8680d58117de Mon Sep 17 00:00:00 2001 From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Tue, 6 Sep 2022 07:19:59 +0300 Subject: [PATCH] Webserver access log to console, different log levels --- .../delivery/webserver/http/AccessLogger.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/http/AccessLogger.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/http/AccessLogger.java index 2cb88b877..5d3558b45 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/http/AccessLogger.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/http/AccessLogger.java @@ -48,7 +48,27 @@ public class AccessLogger { public void log(InternalRequest internalRequest, Request request, Response response) { if (webserverConfiguration.logAccessToConsole()) { - logger.info("Access Log: " + internalRequest.getMethod() + " " + getRequestURI(internalRequest, request) + " (from " + internalRequest.getAccessAddress(webserverConfiguration) + ") - " + response.getCode()); + int code = response.getCode(); + String message = "Access Log: " + internalRequest.getMethod() + " " + + getRequestURI(internalRequest, request) + + " (from " + internalRequest.getAccessAddress(webserverConfiguration) + ") - " + + code; + + int codeFamily = code - (code % 100); // 5XX, 4XX etc + switch (codeFamily) { + case 500: + logger.error(message); + break; + case 400: + logger.warn(message); + break; + case 300: + case 200: + case 100: + default: + logger.info(message); + break; + } } try { dbSystem.getDatabase().executeTransaction(