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>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) AppenderAttachableImpl<IAccessEvent>
aai
static java.lang.String
DEFAULT_CONFIG_FILE
(package private) FilterAttachableImpl<IAccessEvent>
fai
(package private) java.lang.String
fileName
(package private) boolean
quiet
(package private) java.lang.String
resource
(package private) boolean
started
-
Fields inherited from class ch.qos.logback.core.ContextBase
scheduledFutures
-
-
Constructor Summary
Constructors Constructor Description RequestLogImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAppender(Appender<IAccessEvent> newAppender)
Add an appender.private void
addError(java.lang.String msg)
void
addFilter(Filter<IAccessEvent> newFilter)
Add a filter.private void
addInfo(java.lang.String msg)
void
clearAllFilters()
protected void
configure()
void
detachAndStopAllAppenders()
Detach and processPriorToRemoval all previously added appenders.boolean
detachAppender(Appender<IAccessEvent> appender)
Detach the appender passed as parameter from the list of appenders.boolean
detachAppender(java.lang.String name)
Detach the appender with the name passed as parameter from the list of appenders.Appender<IAccessEvent>
getAppender(java.lang.String name)
Get an appender by name.protected java.net.URL
getConfigurationFileURL()
java.util.List<Filter<IAccessEvent>>
getCopyOfAttachedFiltersList()
Get a copy of all the filters contained within this FilterAttachable object.FilterReply
getFilterChainDecision(IAccessEvent event)
Loop through the filters in the chain.boolean
isAttached(Appender<IAccessEvent> appender)
Returnstrue
if the specified appender is in list of attached attached,false
otherwise.boolean
isQuiet()
boolean
isStarted()
java.util.Iterator<Appender<IAccessEvent>>
iteratorForAppenders()
Get an iterator for appenders contained in the parent object.void
log(org.eclipse.jetty.server.Request request, int status, long written)
void
log(org.eclipse.jetty.server.Request jettyRequest, org.eclipse.jetty.server.Response jettyResponse)
private void
runJoranOnFile(java.net.URL configURL)
void
setFileName(java.lang.String fileName)
void
setQuiet(boolean quiet)
void
setResource(java.lang.String resource)
void
start()
void
stop()
-
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 Detail
-
DEFAULT_CONFIG_FILE
public static final java.lang.String DEFAULT_CONFIG_FILE
-
aai
AppenderAttachableImpl<IAccessEvent> aai
-
fai
FilterAttachableImpl<IAccessEvent> fai
-
fileName
java.lang.String fileName
-
resource
java.lang.String resource
-
started
boolean started
-
quiet
boolean quiet
-
-
Method Detail
-
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
private void addInfo(java.lang.String msg)
-
addError
private void addError(java.lang.String msg)
-
start
public void start()
- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classContextBase
-
configure
protected void configure()
-
getConfigurationFileURL
protected java.net.URL getConfigurationFileURL()
-
runJoranOnFile
private void runJoranOnFile(java.net.URL configURL)
-
stop
public void stop()
- Specified by:
stop
in interfaceLifeCycle
- Overrides:
stop
in classContextBase
-
setFileName
public void setFileName(java.lang.String fileName)
-
setResource
public void setResource(java.lang.String resource)
-
isStarted
public boolean isStarted()
- Specified by:
isStarted
in interfaceLifeCycle
- Overrides:
isStarted
in classContextBase
-
isQuiet
public boolean isQuiet()
-
setQuiet
public void setQuiet(boolean quiet)
-
addAppender
public void addAppender(Appender<IAccessEvent> newAppender)
Description copied from interface:AppenderAttachable
Add an appender.- Specified by:
addAppender
in interfaceAppenderAttachable<IAccessEvent>
-
iteratorForAppenders
public java.util.Iterator<Appender<IAccessEvent>> iteratorForAppenders()
Description copied from interface:AppenderAttachable
Get an iterator for appenders contained in the parent object.- Specified by:
iteratorForAppenders
in interfaceAppenderAttachable<IAccessEvent>
-
getAppender
public Appender<IAccessEvent> getAppender(java.lang.String name)
Description copied from interface:AppenderAttachable
Get an appender by name.- Specified by:
getAppender
in interfaceAppenderAttachable<IAccessEvent>
-
isAttached
public boolean isAttached(Appender<IAccessEvent> appender)
Description copied from interface:AppenderAttachable
Returnstrue
if the specified appender is in list of attached attached,false
otherwise.- Specified by:
isAttached
in interfaceAppenderAttachable<IAccessEvent>
-
detachAndStopAllAppenders
public void detachAndStopAllAppenders()
Description copied from interface:AppenderAttachable
Detach and processPriorToRemoval all previously added appenders.- Specified by:
detachAndStopAllAppenders
in interfaceAppenderAttachable<IAccessEvent>
-
detachAppender
public boolean detachAppender(Appender<IAccessEvent> appender)
Description copied from interface:AppenderAttachable
Detach the appender passed as parameter from the list of appenders.- Specified by:
detachAppender
in interfaceAppenderAttachable<IAccessEvent>
-
detachAppender
public boolean detachAppender(java.lang.String name)
Description copied from interface:AppenderAttachable
Detach the appender with the name passed as parameter from the list of appenders.- Specified by:
detachAppender
in interfaceAppenderAttachable<IAccessEvent>
-
addFilter
public void addFilter(Filter<IAccessEvent> newFilter)
Description copied from interface:FilterAttachable
Add a filter.- Specified by:
addFilter
in interfaceFilterAttachable<IAccessEvent>
-
clearAllFilters
public void clearAllFilters()
- Specified by:
clearAllFilters
in interfaceFilterAttachable<IAccessEvent>
-
getCopyOfAttachedFiltersList
public java.util.List<Filter<IAccessEvent>> getCopyOfAttachedFiltersList()
Description copied from interface:FilterAttachable
Get a copy of all the filters contained within this FilterAttachable object.- Specified by:
getCopyOfAttachedFiltersList
in interfaceFilterAttachable<IAccessEvent>
- Returns:
- all attached filters as a list
-
getFilterChainDecision
public FilterReply getFilterChainDecision(IAccessEvent event)
Description copied from interface:FilterAttachable
Loop 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:
getFilterChainDecision
in interfaceFilterAttachable<IAccessEvent>
-
log
public void log(org.eclipse.jetty.server.Request request, int status, long written)
-
-