Logging Service

Turbine's logging service is exceptionally powerful. And it was proprietary. So we ripped it out post Turbine 2.2 and replaced it with commons-logging backed by Log4j. You configure the new logging with a Log4j.properties file which can be configured with the log4j.file property in TurbineResource.properties:

Configuration

# -------------------------------------------------------------------
#
#  L O G 4 J - L O G G I N G
#
# -------------------------------------------------------------------

# Configure log4j from the log4j properties file
log4j.file = WEB-INF/conf/Log4j.properties

If you use another logging system and don't want to configure the log4j subsystem, you can use the empty string or "none" as log4j.file parameter to turn it off.

# -------------------------------------------------------------------
#
#  L O G 4 J - L O G G I N G
#
# -------------------------------------------------------------------

# Do not configure Log4J logging.
log4j.file = none

Log4j Configuration

To use the Logging system, all you need to do is configure some loggers in your Log4j.properties. This is an example how to do it:

# ------------------------------------------------------------------------
#
# Logging Configuration
#
# $Id: logging-service.xml 581455 2007-10-03 01:05:16Z seade $
#
# ------------------------------------------------------------------------

#
# If we don't know the logging facility, put it into the
# turbine.log
#
log4j.rootLogger = INFO, turbine

#
# Turbine goes into Turbine Log
#
log4j.category.org.apache.turbine = INFO, turbine
log4j.additivity.org.apache.turbine = false

#
# Torque has its own log file
#
log4j.category.org.apache.torque = INFO, torque
log4j.additivity.org.apache.torque = false

#
# Velocity Logfile
#
log4j.category.velocity = INFO, velocity
log4j.additivity.velocity = false

#
# Scheduler Category
#
log4j.category.scheduler = INFO, scheduler
log4j.additivity.scheduler = false

########################################################################
#
# Logfile definitions
#
########################################################################

#
# turbine.log
#
log4j.appender.turbine = org.apache.log4j.FileAppender
log4j.appender.turbine.file = ${applicationRoot}/logs/turbine.log
log4j.appender.turbine.layout = org.apache.log4j.PatternLayout
log4j.appender.turbine.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.turbine.append = false

#
# torque.log
#
log4j.appender.torque = org.apache.log4j.FileAppender
log4j.appender.torque.file = ${applicationRoot}/logs/torque.log
log4j.appender.torque.layout = org.apache.log4j.PatternLayout
log4j.appender.torque.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.torque.append = false

#
# Scheduler Output
#
log4j.appender.scheduler = org.apache.log4j.FileAppender
log4j.appender.scheduler.file = ${applicationRoot}/logs/scheduler.log
log4j.appender.scheduler.layout = org.apache.log4j.PatternLayout
log4j.appender.scheduler.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.scheduler.append = false

#
# Velocity gets configured to write its output onto the velocity
# category.
#
log4j.appender.velocity = org.apache.log4j.FileAppender
log4j.appender.velocity.file = ${applicationRoot}/logs/velocity.log
log4j.appender.velocity.layout = org.apache.log4j.PatternLayout
log4j.appender.velocity.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.velocity.append = false

Sub Projects like Torque and Velocity get either configured correctly by their Services (Velocity by the VelocityService) or already know about commons-logging (Torque).

Usage

You use the logging by accessing it via commons-logging. This is an example how to do it.

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

// Provide a logger with the class name as category. This
// is recommended because you can split your log files
// by packages in the Log4j.properties. You can provide
// any other category name here, though.
private Log log = LogFactory.getLog(this.getClass());

log.info("this message would go to any facility configured to use the " + this.getClass().getName() + " Facility");

It is recommended for performance reasons that you provide a class wide logger like this:

package foo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Bar
{
    // Classwide static logger
    private static Log log = LogFactory.getLog(Bar.class);
.
.
.
}