public
Description: The Lift web framework for Scala
Home | Edit | New

How To: Configure Logging

By default, Lift uses log4j for logging, and has a number of conventions established for changing the logging configuration. It is possible to use other logging systems.

Configuration via log4j.xml or log4j.props

You can configure logging by providing a configuration file in src/main/resources/props/. There is a standard naming format that allows the configuration to be based on the run mode, user and host.

The format is:

modeName.hostName.userName.filename.extension

where:

  • modeName is omitted for development mode, but is otherwise one of: production, test, staging, pilot, profile or default.
  • hostName is optional
  • userName is optional
  • filename.extension is either log4j.xml or log4j.props

Lift searches for the the most specific file in the order. For example, on my machine (thunderbolt.lan), where I’m logged in as “richard” running in development mode, the search order is:

  • /props/richard.thunderbolt.lan.log4j.xml
  • /props/richard.log4j.xml
  • /props/thunderbolt.lan.log4j.xml
  • /props/default.log4j.xml
  • /richard.thunderbolt.lan.log4j.xml
  • /richard.log4j.xml
  • /thunderbolt.lan.log4j.xml
  • /default.log4j.xml

In production mode (-Drun.mode=production) the list looks like this:

  • /props/production.richard.thunderbolt.config.log4j.xml
  • /props/production.richard.log4j.xml
  • /props/production.thunderbolt.config.log4j.xml
  • /props/production.default.log4j.xml
  • /production.richard.thunderbolt.config.log4j.xml
  • /production.richard.log4j.xml
  • /production.thunderbolt.config.log4j.xml
  • /production.default.log4j.xml

If you’re having difficulty spotting how log4j is configured, adding a system property of log4j.debug can help. For example:
$ MAVEN_OPTS="-Drun.mode=production -Dlog4j.debug=true" mvn jetty:run

Configuration in Boot.scala

An alternative is to in-line the configuration in your Boot.scala:

def boot {
    LogBoot.defaultProps =
      """<?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">  
      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">  
        <appender name="appender" class="org.apache.log4j.ConsoleAppender">  
          <layout class="org.apache.log4j.SimpleLayout"/>  
        </appender>  
        <root>  
          <priority value="DEBUG"/>  
          <appender-ref ref="appender"/>  
        </root>  
      </log4j:configuration>  
      """ 
 }
Last edited by Xavi-, Mon Aug 31 18:34:19 -0700 2009
Home | Edit | New
Versions: