|
JavaGantt 2011.1 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.beesoft.gaia.log.LogFactory
public abstract class LogFactory
Abstract superclass for all log factories. It serves as a factory of logger
instances for different logging systems. Current factory can be obtained by
method getInstance()
. The typical usage scenario is like this:
LogFactory factory = LogFactory.getInstance (); Log log = factory.getLog ("mypackage.MyClass"); if (log.isDebugEnabled ()) { log.debug ("This is logged message"); }
This class also offers methods setThreadBoundIdentifier(String)
and
getThreadBoundIdentifier()
to create link between current thread and
an identifier defined by programmer. You can use them to log records with
user name, for example. This is useful in server applications, where is
difficult to pair a thread to the active client.
To customize this class to the requested logging system, you have to override
createLog(String)
method for your needs and to subclass the
AbstractLog
class. There are prepared implementations for:
java.util.logging
) systemorg.apache.log4j
) systemorg.apache.commons.logging
) system
To use some of these logging systems you have to configure the underlaying
real subsystem and create a corresponding factory by invoking its constructor
(for example, for Log4J subsystem you need Log4jFactory
instance). Then you can use the pattern from the introduction in your
application.
Constructor Summary | |
---|---|
protected |
LogFactory()
Default constructor. |
Method Summary | |
---|---|
protected abstract Log |
createLog(java.lang.String name)
Creates a new instance of Log . |
static LogFactory |
getInstance()
Returns an instance of the LogFactory. |
Log |
getLog(java.lang.Class<?> clazz)
Returns Log instance for given class. |
Log |
getLog(java.lang.Object object)
Returns Log instance for class of the given object. |
Log |
getLog(java.lang.String name)
Returns Log instance for given class name. |
java.lang.String |
getThreadBoundIdentifier()
Returns an identifier bound to the current thread or null, if no one was set. |
void |
setThreadBoundIdentifier(java.lang.String id)
Binds current thread with given identifier. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected LogFactory()
getInstance()
method).
Method Detail |
---|
public static LogFactory getInstance()
log.factory.class
to get
class name of the factory. If property was not found, uses name of class
JavaLogFactory
. Then
creates instance for found class and returns it.
java.lang.RuntimeException
- if cannot create an instanceprotected abstract Log createLog(java.lang.String name)
Log
. This is
invoked from getLog()
method if log for given
class(name) still does not exists.
public Log getLog(java.lang.String name)
createLog(String)
to get one.
name
- class name for which is log required
public Log getLog(java.lang.Class<?> clazz)
getLog(String)
to
obtain return value.
clazz
- class for which is log required
public Log getLog(java.lang.Object object)
getLog(String)
to obtain return value.
object
- -
object for which class is log required
public void setThreadBoundIdentifier(java.lang.String id)
Invoke this method when you start a new thread and deliver to it an
identifier (such as client / user name, etc). The Log
implementations will query for this thread / identifier mapping to append
it to log record.
id
- - identifier to bind with current threadpublic java.lang.String getThreadBoundIdentifier()
|
JavaGantt 2011.1 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |