Package ch.qos.logback.access.jetty
Class RequestLogImpl
java.lang.Object
ch.qos.logback.core.ContextBase
ch.qos.logback.access.jetty.RequestLogImpl
- All Implemented Interfaces:
Context,AppenderAttachable<IAccessEvent>,FilterAttachable<IAccessEvent>,LifeCycle,PropertyContainer,org.eclipse.jetty.server.RequestLog
public class RequestLogImpl
extends ContextBase
implements org.eclipse.jetty.server.RequestLog, AppenderAttachable<IAccessEvent>, FilterAttachable<IAccessEvent>
This class is logback's implementation of jetty's RequestLog interface.
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.
To configure jetty in order to use RequestLogImpl, the following lines must be added to the jetty configuration file, namely etc/jetty.xml:
<Ref id="requestLog">
<Set name="requestLog">
<New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New>
</Set>
</Ref>
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 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 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.
<Ref id="requestLog">
<Set name="requestLog">
<New id="requestLogImpl" class="ch.qos.logback.access.jetty.RequestLogImpl"></New>
<Set name="fileName">path/to/logback.xml</Set>
</Set>
</Ref>
Here is a sample logback-access.xml file that can be used right away:
<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>
Another configuration file, using SMTPAppender, could be:
<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>
-
Nested Class Summary
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
FieldsModifier and TypeFieldDescription(package private) AppenderAttachableImpl<IAccessEvent> static final String(package private) FilterAttachableImpl<IAccessEvent> (package private) String(package private) boolean(package private) String(package private) booleanFields inherited from class ch.qos.logback.core.ContextBase
scheduledFutures -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAppender(Appender<IAccessEvent> newAppender) Add an appender.private voidvoidaddFilter(Filter<IAccessEvent> newFilter) Add a filter.private voidvoidprotected voidvoidDetach and processPriorToRemoval all previously added appenders.booleandetachAppender(Appender<IAccessEvent> appender) Detach the appender passed as parameter from the list of appenders.booleandetachAppender(String name) Detach the appender with the name passed as parameter from the list of appenders.getAppender(String name) Get an appender by name.protected URLGet a copy of all the filters contained within this FilterAttachable object.Loop through the filters in the chain.booleanisAttached(Appender<IAccessEvent> appender) Returnstrueif the specified appender is in list of attached attached,falseotherwise.booleanisQuiet()booleanGet an iterator for appenders contained in the parent object.voidlog(org.eclipse.jetty.server.Request request, int status, long written) voidlog(org.eclipse.jetty.server.Request jettyRequest, org.eclipse.jetty.server.Response jettyResponse) private voidrunJoranOnFile(URL configURL) voidsetFileName(String fileName) voidsetQuiet(boolean quiet) voidsetResource(String resource) voidstart()voidstop()Methods inherited from class ch.qos.logback.core.ContextBase
addScheduledFuture, getBirthTime, getConfigurationLock, getCopyOfPropertyMap, getExecutorService, getName, getObject, getProperty, getScheduledExecutorService, getScheduledFutures, getStatusManager, initCollisionMaps, putObject, putProperty, register, removeObject, reset, setName, setStatusManager, toString
-
Field Details
-
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:
login interfaceorg.eclipse.jetty.server.RequestLog
-
addInfo
-
addError
-
start
public void start()- Specified by:
startin interfaceLifeCycle- Overrides:
startin classContextBase
-
configure
protected void configure() -
getConfigurationFileURL
-
runJoranOnFile
-
stop
public void stop()- Specified by:
stopin interfaceLifeCycle- Overrides:
stopin classContextBase
-
setFileName
-
setResource
-
isStarted
public boolean isStarted()- Specified by:
isStartedin interfaceLifeCycle- Overrides:
isStartedin classContextBase
-
isQuiet
public boolean isQuiet() -
setQuiet
public void setQuiet(boolean quiet) -
addAppender
Description copied from interface:AppenderAttachableAdd an appender.- Specified by:
addAppenderin interfaceAppenderAttachable<IAccessEvent>
-
iteratorForAppenders
Description copied from interface:AppenderAttachableGet an iterator for appenders contained in the parent object.- Specified by:
iteratorForAppendersin interfaceAppenderAttachable<IAccessEvent>
-
getAppender
Description copied from interface:AppenderAttachableGet an appender by name.- Specified by:
getAppenderin interfaceAppenderAttachable<IAccessEvent>
-
isAttached
Description copied from interface:AppenderAttachableReturnstrueif the specified appender is in list of attached attached,falseotherwise.- Specified by:
isAttachedin interfaceAppenderAttachable<IAccessEvent>
-
detachAndStopAllAppenders
public void detachAndStopAllAppenders()Description copied from interface:AppenderAttachableDetach and processPriorToRemoval all previously added appenders.- Specified by:
detachAndStopAllAppendersin interfaceAppenderAttachable<IAccessEvent>
-
detachAppender
Description copied from interface:AppenderAttachableDetach the appender passed as parameter from the list of appenders.- Specified by:
detachAppenderin interfaceAppenderAttachable<IAccessEvent>
-
detachAppender
Description copied from interface:AppenderAttachableDetach the appender with the name passed as parameter from the list of appenders.- Specified by:
detachAppenderin interfaceAppenderAttachable<IAccessEvent>
-
addFilter
Description copied from interface:FilterAttachableAdd a filter.- Specified by:
addFilterin interfaceFilterAttachable<IAccessEvent>
-
clearAllFilters
public void clearAllFilters()- Specified by:
clearAllFiltersin interfaceFilterAttachable<IAccessEvent>
-
getCopyOfAttachedFiltersList
Description copied from interface:FilterAttachableGet a copy of all the filters contained within this FilterAttachable object.- Specified by:
getCopyOfAttachedFiltersListin interfaceFilterAttachable<IAccessEvent>- Returns:
- all attached filters as a list
-
getFilterChainDecision
Description copied from interface:FilterAttachableLoop through the filters in the chain. As soon as a filter decides on ACCEPT or DENY, then that value is returned. If all of the filters return NEUTRAL, then NEUTRAL is returned.- Specified by:
getFilterChainDecisionin interfaceFilterAttachable<IAccessEvent>
-
log
public void log(org.eclipse.jetty.server.Request request, int status, long written)
-