From f646c1dedbf7211e4a9ae3c64ea7f407d435a896 Mon Sep 17 00:00:00 2001 From: Ryan Aird Date: Thu, 1 Oct 2020 12:14:44 -0600 Subject: [PATCH] Add python style request logging --- .../bluemap/core/webserver/HttpConnection.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/HttpConnection.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/HttpConnection.java index 298e3b3f..afce1467 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/HttpConnection.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/webserver/HttpConnection.java @@ -34,6 +34,9 @@ import java.util.concurrent.TimeUnit; import de.bluecolored.bluemap.core.logger.Logger; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; public class HttpConnection implements Runnable { @@ -66,6 +69,19 @@ public void run() { HttpRequest request = acceptRequest(); HttpResponse response = handler.handle(request); sendResponse(response); + + DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + Date date = new Date(); + Logger.global.logInfo( + connection.getInetAddress().toString() + + " [ " + + dateFormat.format(date) + + " ] \"" + + request.getMethod() + + " " + request.getPath() + + " " + request.getVersion() + + "\" " + + response.getStatusCode().toString()); } catch (InvalidRequestException e){ try { sendResponse(new HttpResponse(HttpStatusCode.BAD_REQUEST));