Skip to content

Commit

Permalink
0005000: Turn on Jetty access logging
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Jun 23, 2021
1 parent 35fe06c commit fc2338c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Expand Up @@ -53,5 +53,6 @@ public class ServerConstants {

public final static String SERVER_ENGINE_URI_INTERCEPTORS = "server.engine.uri.interceptors";

public final static String SERVER_ACCESS_LOG = "server.access.log";
public final static String SERVER_ACCESS_LOG_ENABLED = "server.access.log.enabled";
public final static String SERVER_ACCESS_LOG_FILE = "server.access.log.file";
}
Expand Up @@ -31,6 +31,7 @@
import javax.websocket.server.ServerEndpointConfig;

import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http2.HTTP2Cipher;
Expand Down Expand Up @@ -138,7 +139,9 @@ public enum Mode {

protected boolean allowSelfSignedCerts = true;

protected boolean accessLog = false;
protected boolean accessLogEnabled = false;

protected String accessLogFile;

public SymmetricWebServer() {
this(null, DEFAULT_WEBAPP_DIR);
Expand Down Expand Up @@ -195,7 +198,8 @@ protected void initFromProperties() {
disallowedMethods = serverProperties.get(ServerConstants.SERVER_DISALLOW_HTTP_METHODS, "OPTIONS");
httpsNeedClientAuth = serverProperties.is(ServerConstants.HTTPS_NEED_CLIENT_AUTH, false);
httpsWantClientAuth = serverProperties.is(ServerConstants.HTTPS_WANT_CLIENT_AUTH, false);
accessLog = serverProperties.is(ServerConstants.SERVER_ACCESS_LOG, false);
accessLogEnabled = serverProperties.is(ServerConstants.SERVER_ACCESS_LOG_ENABLED, false);
accessLogFile = serverProperties.get(ServerConstants.SERVER_ACCESS_LOG_FILE);

if (serverProperties.is(ServerConstants.SERVER_HTTP_COOKIES_ENABLED, false)) {
if (CookieHandler.getDefault() == null) {
Expand Down Expand Up @@ -279,9 +283,12 @@ public SymmetricWebServer start(int httpPort, int securePort, Mode mode) throws
webapp.getSessionHandler().getSessionCookieConfig().setSecure(true);
}

if (accessLog) {
server.setRequestLog(new CustomRequestLog(new RequestLogWriter(),
CustomRequestLog.EXTENDED_NCSA_FORMAT));
if (accessLogEnabled) {
RequestLogWriter writer = new RequestLogWriter();
if (StringUtils.isNotBlank(accessLogFile)) {
writer = new RequestLogWriter(accessLogFile);
}
server.setRequestLog(new CustomRequestLog(writer, CustomRequestLog.EXTENDED_NCSA_FORMAT));
}

server.setHandler(webapp);
Expand Down

0 comments on commit fc2338c

Please sign in to comment.