org.beanfabrics.log
Class LoggerFactory
java.lang.Object
org.beanfabrics.log.LoggerFactory
public class LoggerFactory
- extends java.lang.Object
The LoggerFactory
is used for creating (or accessing cached)
Logger
objects. Which logger implementation is used depends on
configuration. At first request the LoggerFactory
chooses
the concrete constructor by evaluating the following rules and
reuses it for every subsequent request.
- The
LoggerFactory
checks if the system property
"org.beanfabrics.log.LoggerFactory.loggerclass" for the name of a valid class
with a valid constructor. The constructor is valid if it is public, returns
an instance of Logger
, and requires a single parameter of type
Class
. This parameter is used as the logging category.
- The
LoggerFactory
checks if slf4j is in the classpath. If that is the
case, the factory uses the constructor of Slf4jLogger
.
- If none of the above is true, the
LoggerFactory
falls back
to the default Jdk14Logger
, that delegates to
Logger
.
Usually Beanfabrics classes store their logger reference in a static field,
hence these logger instances are created when the calling class is loaded by
the classloader.
- See Also:
- Logging Example
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SYSPROPKEY_LOGGER
public static final java.lang.String SYSPROPKEY_LOGGER
- The key of the system property to set a custom
Logger
.
LoggerFactory
public LoggerFactory()
getLogger
public static Logger getLogger(java.lang.Class clazz)
- Returns a the
Logger
instance for a certain Class
.
- Parameters:
clazz
- the Class
the Logger
is for
- Returns:
- the
Logger
instance
setLoggerClass
public static void setLoggerClass(java.lang.Class clazz)
throws java.lang.IllegalArgumentException
- Set the
Class
implementing the Logger
. This class will be
used to create new instances by getLogger(Class)
.
- Parameters:
clazz
- the Class
implementing the Logger
- Throws:
java.lang.IllegalArgumentException
- if clazz
is
null
, does not implement Logger
or has
no constructor with the argument "Class
clazz
"