Split logging into separate function and use tabs instead of spaces'

This commit is contained in:
Ryan Aird 2020-10-03 20:39:26 -06:00
parent a2579f307f
commit ddffdd6102

View File

@ -72,20 +72,9 @@ public void run() {
HttpRequest request = acceptRequest();
HttpResponse response = handler.handle(request);
sendResponse(response);
if (verbose) {
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());
}
if (verbose) {
log(request, response);
}
} catch (InvalidRequestException e){
try {
sendResponse(new HttpResponse(HttpStatusCode.BAD_REQUEST));
@ -109,6 +98,21 @@ public void run() {
Logger.global.logError("Error while closing HttpConnection!", e);
}
}
private void log(HttpRequest request, HttpResponse 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());
}
private void sendResponse(HttpResponse response) throws IOException {
response.write(out);