org.apache.commons.logging

Class LogSource


public class LogSource
extends java.lang.Object

Factory for creating Log instances. Applications should call the makeNewLogInstance() method to instantiate new instances of the configured Log implementation class.

By default, calling getInstance() will use the following algorithm:

You can change the default behavior in one of two ways:

Version:
$Id: LogSource.java,v 1.21 2004/02/28 21:46:45 craigmcc Exp $
Author:
Rod Waldhoff

Field Summary

protected static boolean
jdk14IsAvailable
Is JDK 1.4 logging available
protected static boolean
log4jIsAvailable
Is log4j available (in the current classpath)
protected static Constructor
logImplctor
Constructor for current log class
protected static Hashtable
logs

Constructor Summary

LogSource()
Don't allow others to create instances

Method Summary

static Log
getInstance(Class clazz)
Get a Log instance by class
static Log
getInstance(String name)
Get a Log instance by class name
static String[]
getLogNames()
Returns a String array containing the names of all logs known to me.
static Log
makeNewLogInstance(String name)
Create a new Log implementation, based on the given name.
static void
setLogImplementation(Class logclass)
Set the log implementation/log implementation factory by class.
static void
setLogImplementation(String classname)
Set the log implementation/log implementation factory by the name of the class.

Field Details

jdk14IsAvailable

protected static boolean jdk14IsAvailable
Is JDK 1.4 logging available

log4jIsAvailable

protected static boolean log4jIsAvailable
Is log4j available (in the current classpath)

logImplctor

protected static Constructor logImplctor
Constructor for current log class

logs

protected static Hashtable logs

Constructor Details

LogSource

private LogSource()
Don't allow others to create instances

Method Details

getInstance

public static Log getInstance(Class clazz)
Get a Log instance by class

getInstance

public static Log getInstance(String name)
Get a Log instance by class name

getLogNames

public static String[] getLogNames()
Returns a String array containing the names of all logs known to me.

makeNewLogInstance

public static Log makeNewLogInstance(String name)
Create a new Log implementation, based on the given name.

The specific Log implementation returned is determined by the value of the org.apache.commons.logging.log property. The value of org.apache.commons.logging.log may be set to the fully specified name of a class that implements the Log interface. This class must also have a public constructor that takes a single String argument (containing the name of the Log to be constructed.

When org.apache.commons.logging.log is not set, or when no corresponding class can be found, this method will return a Log4JLogger if the log4j Logger class is available in the LogSource's classpath, or a Jdk14Logger if we are on a JDK 1.4 or later system, or NoOpLog if neither of the above conditions is true.

Parameters:
name - the log name (or category)

setLogImplementation

public static void setLogImplementation(Class logclass)
            throws LinkageError,
                   ExceptionInInitializerError,
                   NoSuchMethodException,
                   SecurityException
Set the log implementation/log implementation factory by class. The given class must implement Log, and provide a constructor that takes a single String argument (containing the name of the log).

setLogImplementation

public static void setLogImplementation(String classname)
            throws LinkageError,
                   ExceptionInInitializerError,
                   NoSuchMethodException,
                   SecurityException,
                   ClassNotFoundException
Set the log implementation/log implementation factory by the name of the class. The given class must implement Log, and provide a constructor that takes a single String argument (containing the name of the log).

Copyright 2002-2004 The Apache Software Foundation.