Commons MMBaseLogging

Every application needs some sort of logging. The Jakarta commons-logging is a good choice because it is simple and logger implementations can be plugged in. Most mmapps use commons-logging. The commons-logging package usually can auto detects the underlaying loggin system and is able to use the logger if configured. The commons-logging package is not able to detect the MMBase log API. And thus might use log4j or write output to stdout. The result is that you don't have much control over what is logged. This mmapps provides an adapter so that messages logged with commons-logging are logged via the MMBase Logging API.

This package is only useful when you run MMBase.

configuring

The commons-mmbaselogging jar contains a commons-logging.properties file. commons-logging will search for that file to configure it self so if everything goes well there is nothing to configure. It you still have problems or use a version prior to 1.3 you follow the next instructions

The simplest way to configure commons-logging to use commons-mmbaselogging is to give an extra parameter to the Java Virtual Machine

-Dorg.apache.commons.logging.LogFactory=net.sf.mmapps.commons.logging.impl.MMBaseLoggingFactory


If you run MMBase in a servlet container that also uses commons-logging (like Tomcat 5) this approach will not work since every call to commons-logging will try to use commons-mmbaselogging. It that case you need to configure only the webapp that runs MMBase , this is done by creating a property file in the WEB-INF/classes called commons-logging.properties

org.apache.commons.logging.LogFactory=net.sf.mmapps.commons.logging.impl.MMBaseLoggingFactory

How to use commons-logging

Using commons-logging is very simple

import org.apache.commons.logging.*
public class Demo{
    private static Log log = LogFactory.getLog(Demo.class);
    public void test(){
        log.info("testing logging");
    }
}