Class RequestLogImpl

  • All Implemented Interfaces:
    Context, AppenderAttachable<IAccessEvent>, FilterAttachable<IAccessEvent>, LifeCycle, PropertyContainer, org.eclipse.jetty.server.RequestLog, org.eclipse.jetty.util.component.LifeCycle

    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>
     
    Author:
    Ceki Gülcü, Sébastien Pennec
    • Field Detail

      • DEFAULT_CONFIG_FILE

        public static final java.lang.String DEFAULT_CONFIG_FILE
    • Constructor Detail

      • RequestLogImpl

        public RequestLogImpl()
    • Method Detail

      • log

        public void log​(org.eclipse.jetty.server.Request jettyRequest,
                        org.eclipse.jetty.server.Response jettyResponse)
        Specified by:
        log in interface org.eclipse.jetty.server.RequestLog
      • start

        public void start()
        Specified by:
        start in interface LifeCycle
        Specified by:
        start in interface org.eclipse.jetty.util.component.LifeCycle
        Overrides:
        start in class ContextBase
      • configure

        protected void configure()
      • getConfigurationFileURL

        protected java.net.URL getConfigurationFileURL()
      • stop

        public void stop()
        Specified by:
        stop in interface LifeCycle
        Specified by:
        stop in interface org.eclipse.jetty.util.component.LifeCycle
        Overrides:
        stop in class ContextBase
      • isRunning

        public boolean isRunning()
        Specified by:
        isRunning in interface org.eclipse.jetty.util.component.LifeCycle
      • setFileName

        public void setFileName​(java.lang.String fileName)
      • setResource

        public void setResource​(java.lang.String resource)
      • isStarted

        public boolean isStarted()
        Specified by:
        isStarted in interface LifeCycle
        Specified by:
        isStarted in interface org.eclipse.jetty.util.component.LifeCycle
        Overrides:
        isStarted in class ContextBase
      • isStarting

        public boolean isStarting()
        Specified by:
        isStarting in interface org.eclipse.jetty.util.component.LifeCycle
      • isStopping

        public boolean isStopping()
        Specified by:
        isStopping in interface org.eclipse.jetty.util.component.LifeCycle
      • isStopped

        public boolean isStopped()
        Specified by:
        isStopped in interface org.eclipse.jetty.util.component.LifeCycle
      • isFailed

        public boolean isFailed()
        Specified by:
        isFailed in interface org.eclipse.jetty.util.component.LifeCycle
      • isQuiet

        public boolean isQuiet()
      • setQuiet

        public void setQuiet​(boolean quiet)
      • addLifeCycleListener

        public void addLifeCycleListener​(org.eclipse.jetty.util.component.LifeCycle.Listener listener)
        Specified by:
        addLifeCycleListener in interface org.eclipse.jetty.util.component.LifeCycle
      • removeLifeCycleListener

        public void removeLifeCycleListener​(org.eclipse.jetty.util.component.LifeCycle.Listener listener)
        Specified by:
        removeLifeCycleListener in interface org.eclipse.jetty.util.component.LifeCycle