From d377a5a6388aa7a6a1349abce638da8350d38121 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Thu, 27 Jan 2022 07:32:55 -0600 Subject: [PATCH] ARTEMIS-3658 remove refs to Jetty's deprecated NCSARequestLog --- .../activemq/artemis/dto/RequestLogDTO.java | 13 +++ .../artemis/component/WebServerComponent.java | 80 +++++++------------ docs/user-manual/en/web-server.md | 31 ++++--- 3 files changed, 60 insertions(+), 64 deletions(-) diff --git a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/RequestLogDTO.java b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/RequestLogDTO.java index b2522e6890..ec6097984a 100644 --- a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/RequestLogDTO.java +++ b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/RequestLogDTO.java @@ -46,12 +46,14 @@ public class RequestLogDTO { /** * logging of the request cookies */ + @Deprecated @XmlAttribute public Boolean logCookies; /** * the output file name of the request log */ + @Deprecated @XmlAttribute public String logTimeZone; @@ -76,30 +78,41 @@ public class RequestLogDTO { /** * the timestamp format string for request log entries */ + @Deprecated @XmlAttribute public String logDateFormat; /** * the locale of the request log */ + @Deprecated @XmlAttribute public String logLocale; /** * logging of request processing time */ + @Deprecated @XmlAttribute public Boolean logLatency; /** * logging of the request hostname */ + @Deprecated @XmlAttribute public Boolean logServer; /** * whether the actual IP address of the connection or the IP address from the X-Forwarded-For header will be logged */ + @Deprecated @XmlAttribute public Boolean preferProxiedForAddress; + + /** + * the format to use for logging; see https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/server/CustomRequestLog.html + */ + @XmlAttribute + public String format; } diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java index b7087092bd..8027929c0d 100644 --- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java +++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java @@ -16,6 +16,17 @@ */ package org.apache.activemq.artemis.component; +import javax.servlet.DispatcherType; +import java.io.File; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.stream.Collectors; + import org.apache.activemq.artemis.ActiveMQWebLogger; import org.apache.activemq.artemis.components.ExternalComponent; import org.apache.activemq.artemis.dto.AppDTO; @@ -24,9 +35,10 @@ import org.apache.activemq.artemis.dto.ComponentDTO; import org.apache.activemq.artemis.dto.WebServerDTO; import org.eclipse.jetty.security.DefaultAuthenticatorFactory; import org.eclipse.jetty.server.ConnectionFactory; +import org.eclipse.jetty.server.CustomRequestLog; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; -import org.eclipse.jetty.server.NCSARequestLog; +import org.eclipse.jetty.server.RequestLogWriter; import org.eclipse.jetty.server.SecureRequestCustomizer; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; @@ -41,18 +53,6 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.webapp.WebAppContext; import org.jboss.logging.Logger; -import javax.servlet.DispatcherType; -import java.io.File; -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - public class WebServerComponent implements ExternalComponent { private static final Logger logger = Logger.getLogger(WebServerComponent.class); @@ -209,34 +209,30 @@ public class WebServerComponent implements ExternalComponent { } private RequestLogHandler getLogHandler() { - RequestLogHandler requestLogHandler = new RequestLogHandler(); - NCSARequestLog requestLog = new NCSARequestLog(); + RequestLogWriter requestLogWriter = new RequestLogWriter(); + CustomRequestLog requestLog; // required via config so no check necessary - requestLog.setFilename(webServerConfig.requestLog.filename); + requestLogWriter.setFilename(webServerConfig.requestLog.filename); if (webServerConfig.requestLog.append != null) { - requestLog.setAppend(webServerConfig.requestLog.append); - } - - if (webServerConfig.requestLog.extended != null) { - requestLog.setExtended(webServerConfig.requestLog.extended); - } - - if (webServerConfig.requestLog.logCookies != null) { - requestLog.setLogCookies(webServerConfig.requestLog.logCookies); - } - - if (webServerConfig.requestLog.logTimeZone != null) { - requestLog.setLogTimeZone(webServerConfig.requestLog.logTimeZone); + requestLogWriter.setAppend(webServerConfig.requestLog.append); } if (webServerConfig.requestLog.filenameDateFormat != null) { - requestLog.setFilenameDateFormat(webServerConfig.requestLog.filenameDateFormat); + requestLogWriter.setFilenameDateFormat(webServerConfig.requestLog.filenameDateFormat); } if (webServerConfig.requestLog.retainDays != null) { - requestLog.setRetainDays(webServerConfig.requestLog.retainDays); + requestLogWriter.setRetainDays(webServerConfig.requestLog.retainDays); + } + + if (webServerConfig.requestLog.format != null) { + requestLog = new CustomRequestLog(requestLogWriter, webServerConfig.requestLog.format); + } else if (webServerConfig.requestLog.extended != null && webServerConfig.requestLog.extended) { + requestLog = new CustomRequestLog(requestLogWriter, CustomRequestLog.EXTENDED_NCSA_FORMAT); + } else { + requestLog = new CustomRequestLog(requestLogWriter, CustomRequestLog.NCSA_FORMAT); } if (webServerConfig.requestLog.ignorePaths != null && webServerConfig.requestLog.ignorePaths.length() > 0) { @@ -248,28 +244,8 @@ public class WebServerComponent implements ExternalComponent { requestLog.setIgnorePaths(ignorePaths); } - if (webServerConfig.requestLog.logDateFormat != null) { - requestLog.setLogDateFormat(webServerConfig.requestLog.logDateFormat); - } - - if (webServerConfig.requestLog.logLocale != null) { - requestLog.setLogLocale(Locale.forLanguageTag(webServerConfig.requestLog.logLocale)); - } - - if (webServerConfig.requestLog.logLatency != null) { - requestLog.setLogLatency(webServerConfig.requestLog.logLatency); - } - - if (webServerConfig.requestLog.logServer != null) { - requestLog.setLogServer(webServerConfig.requestLog.logServer); - } - - if (webServerConfig.requestLog.preferProxiedForAddress != null) { - requestLog.setPreferProxiedForAddress(webServerConfig.requestLog.preferProxiedForAddress); - } - + RequestLogHandler requestLogHandler = new RequestLogHandler(); requestLogHandler.setRequestLog(requestLog); - return requestLogHandler; } diff --git a/docs/user-manual/en/web-server.md b/docs/user-manual/en/web-server.md index 8008e953ea..3a01bd45ba 100644 --- a/docs/user-manual/en/web-server.md +++ b/docs/user-manual/en/web-server.md @@ -68,23 +68,30 @@ It's also possible to configure HTTP/S request logging via the `request-log` element which has the following attributes: - `filename` The full path of the request log. This attribute is required. -- `append` Whether or not to append to the existing log or truncate it. Boolean flag. -- `extended` Whether or not to use the extended request log format. Boolean flag. -- `logCookies` Logging of the request cookies. Boolean flag. -- `logTimeZone` The output file name of the request log. +- `append` Whether or not to append to the existing log or truncate it. Boolean + flag. +- `extended` Whether or not to use the extended request log format. Boolean + flag. If `true` will use the format `%{client}a - %u %t "%r" %s %O + "%{Referer}i" "%{User-Agent}i"`. If `false` will use the format `%{client}a - + %u %t "%r" %s %O`. Default is `false`. See the [format + specification](https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/server/CustomRequestLog.html) + for more details. - `filenameDateFormat` The log file name date format. - `retainDays` The number of days before rotated log files are deleted. - `ignorePaths` Request paths that will not be logged. Comma delimited list. -- `logDateFormat` The timestamp format string for request log entries. -- `logLocale` The locale of the request log. -- `logLatency` Logging of request processing time. Boolean flag. -- `logServer` Logging of the request hostname. Boolean flag. -- `preferProxiedForAddress` Whether the actual IP address of the connection or - the IP address from the `X-Forwarded-For` header will be logged. Boolean flag. +- `format` Custom format to use. If set this will override `extended`. See the + [format specification](https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/server/CustomRequestLog.html) + for more details. + +The following options were previously supported, but they were replaced by the +`format`: `logCookie`, `logTimeZone`, `logDateFormat`, `logLocale`, +`logLatency`, `logServer`, `preferProxiedForAddress`. All these options are now +deprecated and ignored. These attributes are essentially passed straight through to the underlying -[`org.eclipse.jetty.server.NCSARequestLog`](https://www.eclipse.org/jetty/javadoc/current/org/eclipse/jetty/server/NCSARequestLog.html) -instance. Default values are based on this implementation. +[`org.eclipse.jetty.server.CustomRequestLog`](https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/server/CustomRequestLog.html) +and [`org.eclipse.jetty.server.RequestLogWriter`](https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/server/RequestLogWriter.html) +instances. Default values are based on these implementations. Here is an example configuration: