Add python style request logging

This commit is contained in:
Ryan Aird 2020-10-01 12:14:44 -06:00
parent fea7d9a1cd
commit f646c1dedb

View File

@ -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));