- All Implemented Interfaces:
ch.qos.logback.core.Context
,ch.qos.logback.core.spi.AppenderAttachable<IAccessEvent>
,ch.qos.logback.core.spi.FilterAttachable<IAccessEvent>
,ch.qos.logback.core.spi.LifeCycle
,ch.qos.logback.core.spi.PropertyContainer
,org.eclipse.jetty.server.RequestLog
,org.eclipse.jetty.util.component.LifeCycle
It can be seen as logback classic's LoggerContext. Appenders can be attached directly to RequestLogImpl and RequestLogImpl uses the same StatusManager as LoggerContext does. It also provides containers for properties.
Supported Jetty Versions
This RequestLogImpl
only supports Jetty 7.0.0 through Jetty 10.
If you are using Jetty 11 with the new Jakarta Servlets (namespace jakarta.servlet
)
then you will need a more modern version of logback-access
.
Configuring for Jetty 9.4.x through to Jetty 10.0.x
Jetty 9.4.x and Jetty 10.x use a modern org.eclipse.jetty.server.Server.setRequestLog(RequestLog)
interface that is based on a Server level RequestLog behavior. This means all requests are logged,
even bad requests, and context-less requests.
The internals of the Jetty Request and Response objects track the state of the object at the time
they are committed (the actual state during the application when an action on the network commits the
request/response exchange). This prevents behaviors from 3rd party libraries
that change the state of the request / response before the RequestLog gets a chance
to log the details. This differs from Jetty 9.3.x and
older in that those versions used a (now deprecated) RequestLogHandler
and
would never see bad requests, or context-less requests,
and if a 3rd party library modifies the the response (for example by setting
response.setStatus(200)
after the response has been initiated on the network)
this change in status would be logged, instead of the actual status that was sent.
First, you must be using the proper ${jetty.home}
and ${jetty.base}
directory split. Configure your ${jetty.base}
with at least the `resources` module
enabled (so that your configuration can be found).
Next, create a ${jetty.base}/etc/logback-access.xml
file with the following
content.
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <Set name="requestLog"> <New id="LogbackAccess" class="ch.qos.logback.access.jetty.RequestLogImpl"> <Set name="resource">logback-access.xml</Set> </New> </Set> </Configure>
Now you'll need a ${jetty.base}/resources/logback-access.xml
configuration file.
By default, RequestLogImpl
looks for a logback configuration file called
etc/logback-access.xml
, in the ${jetty.base}
directory, then
the older ${jetty.home}
directory.
The logback-access.xml
file is slightly
different than the usual logback classic configuration file. Most of it is
the same: Appenders
and layouts
are declared the exact same way. However,
loggers elements are not allowed.
It is possible to place the logback configuration file anywhere, as long as it's path is specified. Here is another example, with an arbitrary path to the logback-access.xml file.
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <Set name="requestLog"> <New id="LogbackAccess" class="ch.qos.logback.access.jetty.RequestLogImpl"> <Set name="fileName">/arbitrary/path/to/logback-access.xml</Set> </New> </Set> </Configure>
Configuring for Jetty 7.x thru to Jetty 9.3.x
To configure these older Jetty instances to use RequestLogImpl
,
the use of the RequestLogHandler
is the technique available to you.
Modify your etc/jetty-requestlog.xml
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <Ref id="Handlers"> <Call name="addHandler"> <Arg> <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"> <Set name="requestLog"> <New id="RequestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"/> </Set> </New> </Arg> </Call> </Ref> </Configure>
By default, RequestLogImpl looks for a logback configuration file called logback-access.xml, in the same folder where jetty.xml is located, that is etc/logback-access.xml. The logback-access.xml file is slightly different from the usual logback classic configuration file. Most of it is the same: Appenders and Layouts are declared the exact same way. However, loggers elements are not allowed.
It is possible to put the logback configuration file anywhere, as long as it's path is specified. Here is another example, with a path to the logback-access.xml file.
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> <Configure id="Server" class="org.eclipse.jetty.server.Server"> <Ref id="Handlers"> <Call name="addHandler"> <Arg> <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"> <Set name="requestLog"> <New id="RequestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"> <Set name="fileName">path/to/logback-access.xml</Set> </New> </Set> </New> </Arg> </Call> </Ref> </Configure>
Next is a sample logback-access.xml file printing access events on the console.
<configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.access.PatternLayout"> <param name="Pattern" value="%date %server %remoteIP %clientHost %user %requestURL" /> </layout> </appender> <appender-ref ref="STDOUT" /> </configuration>
Here is another configuration file, using SMTPAppender:
<configuration> <appender name="SMTP" class="ch.qos.logback.access.net.SMTPAppender"> <layout class="ch.qos.logback.access.PatternLayout"> <param name="pattern" value="%remoteIP [%date] %requestURL %statusCode %bytesSent" /> </layout> <param name="From" value="sender@domaine.org" /> <param name="SMTPHost" value="mail.domain.org" /> <param name="Subject" value="Last Event: %statusCode %requestURL" /> <param name="To" value="server_admin@domain.org" /> </appender> <appender-ref ref="SMTP" /> </configuration>
- Author:
- Ceki Gülcü, Sébastien Pennec, Joakim Erdfelt
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener
Nested classes/interfaces inherited from interface org.eclipse.jetty.server.RequestLog
org.eclipse.jetty.server.RequestLog.Collection, org.eclipse.jetty.server.RequestLog.Writer
-
Field Summary
Fields inherited from class ch.qos.logback.core.ContextBase
configurationLock, scheduledFutures
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAppender
(ch.qos.logback.core.Appender<IAccessEvent> newAppender) boolean
addEventListener
(EventListener listener) void
addFilter
(ch.qos.logback.core.filter.Filter<IAccessEvent> newFilter) protected void
void
addLifeCycleListener
(org.eclipse.jetty.util.component.LifeCycle.Listener listener) void
protected void
void
boolean
detachAppender
(ch.qos.logback.core.Appender<IAccessEvent> appender) boolean
detachAppender
(String name) ch.qos.logback.core.Appender
<IAccessEvent> getAppender
(String name) protected URL
List
<ch.qos.logback.core.filter.Filter<IAccessEvent>> ch.qos.logback.core.spi.FilterReply
boolean
isAttached
(ch.qos.logback.core.Appender<IAccessEvent> appender) boolean
isFailed()
boolean
isQuiet()
boolean
boolean
boolean
boolean
boolean
Iterator
<ch.qos.logback.core.Appender<IAccessEvent>> void
log
(org.eclipse.jetty.server.Request jettyRequest, org.eclipse.jetty.server.Response jettyResponse) boolean
removeEventListener
(EventListener listener) void
removeLifeCycleListener
(org.eclipse.jetty.util.component.LifeCycle.Listener listener) void
setFileName
(String fileName) void
setQuiet
(boolean quiet) void
setResource
(String resource) void
start()
void
stop()
Methods inherited from class ch.qos.logback.core.ContextBase
addConfigurationEventListener, addScheduledFuture, addSubstitutionProperty, fireConfigurationEvent, getAlternateExecutorService, getBirthTime, getConfigurationLock, getCopyOfPropertyMap, getCopyOfScheduledFutures, getExecutorService, getName, getObject, getProperty, getScheduledExecutorService, getScheduledFutures, getSequenceNumberGenerator, getStatusManager, initCollisionMaps, putObject, putProperty, register, removeConfigurationEventListener, removeObject, reset, setName, setSequenceNumberGenerator, setStatusManager, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.qos.logback.core.spi.PropertyContainer
addSubstitutionProperties
-
Field Details
-
DEFAULT_CONFIG_FILE
-
-
Constructor Details
-
RequestLogImpl
public RequestLogImpl()
-
-
Method Details
-
log
public void log(org.eclipse.jetty.server.Request jettyRequest, org.eclipse.jetty.server.Response jettyResponse) - Specified by:
log
in interfaceorg.eclipse.jetty.server.RequestLog
-
addInfo
-
start
- Specified by:
start
in interfacech.qos.logback.core.spi.LifeCycle
- Specified by:
start
in interfaceorg.eclipse.jetty.util.component.LifeCycle
- Overrides:
start
in classch.qos.logback.core.ContextBase
-
configure
-
getConfigurationFileURL
-
stop
- Specified by:
stop
in interfacech.qos.logback.core.spi.LifeCycle
- Specified by:
stop
in interfaceorg.eclipse.jetty.util.component.LifeCycle
- Overrides:
stop
in classch.qos.logback.core.ContextBase
-
isRunning
- Specified by:
isRunning
in interfaceorg.eclipse.jetty.util.component.LifeCycle
-
setFileName
-
setResource
-
isStarted
- Specified by:
isStarted
in interfacech.qos.logback.core.spi.LifeCycle
- Specified by:
isStarted
in interfaceorg.eclipse.jetty.util.component.LifeCycle
- Overrides:
isStarted
in classch.qos.logback.core.ContextBase
-
isStarting
- Specified by:
isStarting
in interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isStopping
- Specified by:
isStopping
in interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isStopped
- Specified by:
isStopped
in interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isFailed
- Specified by:
isFailed
in interfaceorg.eclipse.jetty.util.component.LifeCycle
-
addEventListener
- Specified by:
addEventListener
in interfaceorg.eclipse.jetty.util.component.LifeCycle
-
removeEventListener
- Specified by:
removeEventListener
in interfaceorg.eclipse.jetty.util.component.LifeCycle
-
isQuiet
-
setQuiet
-
addAppender
- Specified by:
addAppender
in interfacech.qos.logback.core.spi.AppenderAttachable<IAccessEvent>
-
iteratorForAppenders
- Specified by:
iteratorForAppenders
in interfacech.qos.logback.core.spi.AppenderAttachable<IAccessEvent>
-
getAppender
- Specified by:
getAppender
in interfacech.qos.logback.core.spi.AppenderAttachable<IAccessEvent>
-
isAttached
- Specified by:
isAttached
in interfacech.qos.logback.core.spi.AppenderAttachable<IAccessEvent>
-
detachAndStopAllAppenders
- Specified by:
detachAndStopAllAppenders
in interfacech.qos.logback.core.spi.AppenderAttachable<IAccessEvent>
-
detachAppender
- Specified by:
detachAppender
in interfacech.qos.logback.core.spi.AppenderAttachable<IAccessEvent>
-
detachAppender
- Specified by:
detachAppender
in interfacech.qos.logback.core.spi.AppenderAttachable<IAccessEvent>
-
addFilter
- Specified by:
addFilter
in interfacech.qos.logback.core.spi.FilterAttachable<IAccessEvent>
-
clearAllFilters
- Specified by:
clearAllFilters
in interfacech.qos.logback.core.spi.FilterAttachable<IAccessEvent>
-
getCopyOfAttachedFiltersList
- Specified by:
getCopyOfAttachedFiltersList
in interfacech.qos.logback.core.spi.FilterAttachable<IAccessEvent>
-
getFilterChainDecision
- Specified by:
getFilterChainDecision
in interfacech.qos.logback.core.spi.FilterAttachable<IAccessEvent>
-
addLifeCycleListener
-
removeLifeCycleListener
-