aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorjcardus <joaquim.cardeira@gmail.com>2020-04-21 01:50:58 +0100
committerGitHub <noreply@github.com>2020-04-20 17:50:58 -0700
commitbe4a9566fd67fc3f42888df75949163438db809c (patch)
tree94cb5e461d8ec0491631bcd8ac763d051c166e73 /src/main/java/org
parent29ae25be34fc55893eaed84603d7cb45a670ea0a (diff)
downloadtrackermap-server-be4a9566fd67fc3f42888df75949163438db809c.tar.gz
trackermap-server-be4a9566fd67fc3f42888df75949163438db809c.tar.bz2
trackermap-server-be4a9566fd67fc3f42888df75949163438db809c.zip
Adding jetty log (#4516)
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/config/Keys.java20
-rw-r--r--src/main/java/org/traccar/web/WebServer.java11
2 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 200ef8aa3..b31861c88 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -402,6 +402,26 @@ public final class Keys {
public static final ConfigKey LOCATION_LONGITUDE_HEMISPHERE = new ConfigKey(
"location.longitudeHemisphere", Boolean.class);
+ /**
+ * Enable Jetty Request Log.
+ */
+ public static final ConfigKey WEB_REQUEST_LOG_ENABLE = new ConfigKey(
+ "web.requestLog.enable", Boolean.class);
+
+ /**
+ * Jetty Request Log Path.
+ * The path must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
+ * Example: ./logs/jetty-yyyy_mm_dd.request.log
+ */
+ public static final ConfigKey WEB_REQUEST_LOG_PATH = new ConfigKey(
+ "web.requestLog.path", String.class);
+
+ /**
+ * Set the number of days before rotated request log files are deleted.
+ */
+ public static final ConfigKey WEB_REQUEST_LOG_RETAIN_DAYS = new ConfigKey(
+ "web.requestLog.retainDays", Integer.class);
+
private Keys() {
}
diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java
index d5c4cf71b..1f71bebc3 100644
--- a/src/main/java/org/traccar/web/WebServer.java
+++ b/src/main/java/org/traccar/web/WebServer.java
@@ -18,6 +18,7 @@ package org.traccar.web;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.proxy.AsyncProxyServlet;
+import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ErrorHandler;
@@ -39,6 +40,7 @@ import org.traccar.api.ObjectMapperProvider;
import org.traccar.api.ResourceErrorHandler;
import org.traccar.api.SecurityRequestFilter;
import org.traccar.api.resource.ServerResource;
+import org.traccar.config.Keys;
import javax.servlet.DispatcherType;
import javax.servlet.ServletException;
@@ -100,6 +102,15 @@ public class WebServer {
handlers.addHandler(servletHandler);
handlers.addHandler(new GzipHandler());
server.setHandler(handlers);
+
+ if (config.getBoolean(Keys.WEB_REQUEST_LOG_ENABLE)) {
+ NCSARequestLog requestLog = new NCSARequestLog(config.getString(Keys.WEB_REQUEST_LOG_PATH));
+ requestLog.setAppend(true);
+ requestLog.setExtended(true);
+ requestLog.setLogLatency(true);
+ requestLog.setRetainDays(config.getInteger(Keys.WEB_REQUEST_LOG_RETAIN_DAYS));
+ server.setRequestLog(requestLog);
+ }
}
private void initClientProxy(Config config, HandlerList handlers) {