com.opensymphony.provider.log
Class Log4JProvider

java.lang.Object
  extended bycom.opensymphony.provider.log.Log4JProvider
All Implemented Interfaces:
LogProvider, Provider

public class Log4JProvider
extends Object
implements LogProvider

LogProvider that uses Categories of Log4J, see the Log4J website for more details.

There are corresponding methods for isDebugEnabled() , isInfoEnabled() etc. to save the overhead of building the log string if the appropriate level is not set, as follows:


     if ( logger.isInfoEnabled() ) logger.info( "This " + methodCall() + " and the string "
                                              + "concatenation will only take place if "
                                              + "INFO debugging is currently enabled" );

 

A configuration file should be used by setting the logger.config system property which will be processed using PropertyConfigurator.

Version:
$Revision: 1.1.1.1 $
Author:
Joe Walnes, Mike Cannon-Brookes, Dan North

Field Summary
 
Fields inherited from interface com.opensymphony.provider.LogProvider
DEBUG, ERROR, FATAL, INFO, WARN
 
Constructor Summary
Log4JProvider()
           
 
Method Summary
 void destroy()
          Shutdown Provider.
 Object getContext(String name)
          Get object representing context of logger.
 void init()
          Setup Configurator.
 boolean isEnabled(Object context, int level)
          Check whether logging is enabled for particular context/level combination.
 void log(Object context, int level, Object msg, Throwable throwable)
          Log a message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log4JProvider

public Log4JProvider()
Method Detail

getContext

public Object getContext(String name)
Description copied from interface: LogProvider
Get object representing context of logger. (For example with Log4J, Category). This object is not used anywhere, except when it is passed back to the log() or isEnabled() methods.

Specified by:
getContext in interface LogProvider

isEnabled

public boolean isEnabled(Object context,
                         int level)
Description copied from interface: LogProvider
Check whether logging is enabled for particular context/level combination.

Specified by:
isEnabled in interface LogProvider

destroy

public void destroy()
Description copied from interface: Provider
Shutdown Provider.

Specified by:
destroy in interface Provider

init

public void init()
          throws ProviderConfigurationException
Setup Configurator. Looks for configuration information in the following order: - System property "logger.config" which is the path to a log4j properties file on disk - /oscore.lcf which is a log4j config file in the classpath

Specified by:
init in interface Provider
Throws:
ProviderConfigurationException - thrown if error in startup or configuration.

log

public void log(Object context,
                int level,
                Object msg,
                Throwable throwable)
Description copied from interface: LogProvider
Log a message.

Specified by:
log in interface LogProvider

OSCore Project Page