How-to: Modify the logging configuration for the embedded Jetty server

The Pineapple web application is running in an Jetty web server. Two types of logging can be modified for the Jetty server:

  • The server log, which contains entries of the internal functioning of the Jetty server.
  • The request log, which contains entries of all HTTP requests to the server.

Two examples are included:

  • How to change the logging configuration of the server log.
  • How to change the logging configuration of the request log.

How to change the logging configuration of the server log

The unzipped client contains the directory layout:

pineapple-standalone-web-client-VERSION
     |     
     +--- runPineapple.cmd
     +--- runPineapple.sh     
     |     
     +--- bin     
     |     +--- helper scripts     
     |          
     +--- conf     
     |     +--- log4j.properties
     |     `--- jetty.xml
     |               
     +--- resources
     |     `--- jetty-logging.properties
     |               
     +--- webapps
     |     `--- pineapple-web-application-war.war
     |               
     +--- lib
           +--- pineapple-jetty-starter-1.0.jar
           +--- jetty-*.jar
           +--- log4j-1.2.14.jar
           +--- slf4j-api-1.7.7.jar           
           +--- slf4j-log4j12-1.7.7.jar           
           `--- servlet-api-3.1.0.jar

The Pineapple log configuration is configured in the pineapple-standalone-web-client-${pineapple.release.version}/conf/log4j.properties file:

# Set root logger to INFO and add an appender called PINEAPPLE_FILE
log4j.rootLogger=INFO, PINEAPPLE_FILE

# PINEAPPLE_FILE is set to be a file appender
log4j.appender.PINEAPPLE_FILE=org.apache.log4j.RollingFileAppender
log4j.appender.PINEAPPLE_FILE.file=${pineapple.home.dir}/logs/pineapple-web-application.log
log4j.appender.PINEAPPLE_FILE.MaxFileSize=10MB
log4j.appender.PINEAPPLE_FILE.MaxBackupIndex=5
log4j.appender.PINEAPPLE_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.PINEAPPLE_FILE.layout.ConversionPattern=<%d{ISO8601}> <%p> <%C{1}> <%m>%n

The server log is configured to log in ${pineapple.home.dir}/logs/pineapple-web-application.log.

To change the logging configuration, simple modify any of the logging attributes. The application must be restarted for the reconfiguration to take effect.

How to change the logging configuration for the request log

Request logging is be default disabled in Pineapple.

The Jetty request log can be configured in the pineapple-standalone-web-client-${pineapple.release.version}/conf/jetty.xml file in the section:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">

        <!-- a lot of server configuration here..... -->

    <!-- =========================================================== -->
    <!-- Configure Request Log                                       -->
    <!-- =========================================================== -->        
        <Ref id="RequestLog">
          <Set name="requestLog">
            <New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog">
              <Arg><SystemProperty name="pineapple.home.dir" default="./logs"/>/logs/pineapple-web-application-jetty-requests.log</Arg>         
              <Set name="retainDays">90</Set>
              <Set name="append">true</Set>
              <Set name="extended">false</Set>
              <Set name="LogTimeZone">GMT</Set>
             </New>
          </Set>
        </Ref>  

        <!-- ...and more server configuration here..... -->
        
</Configure>    

The request log is configured to log in ${pineapple.home.dir}/logs/pineapple-web-application-jetty-requests.log.

To change the logging configuration, simple modify any of the logging attributes. The application must be restarted for the reconfiguration to take effect.