org.x4juli
Class ClassLoaderLogManager

java.lang.Object
  extended byjava.util.logging.LogManager
      extended byorg.x4juli.ClassLoaderLogManager
All Implemented Interfaces:
LoggerClassInformation, LoggerRepositoryHolder
Direct Known Subclasses:
X4JuliLogManager

public class ClassLoaderLogManager
extends java.util.logging.LogManager
implements LoggerRepositoryHolder, LoggerClassInformation

Per classloader LogManager implementation. Based on Version 1.11 Apache Tomcat JULI

Since:
0.5
Author:
Remy Maucherat, Boris Unckel

Nested Class Summary
protected static class ClassLoaderLogManager.ClassLoaderLogInfo
          Repository for loggers, nodes, handlers, properties for each classloader.
protected static class ClassLoaderLogManager.LogNode
          A LogNode represents one step in a namespace of Loggers.
private static class ClassLoaderLogManager.RootLogger
          This class is needed to instantiate the root of each per classloader hierarchy.
 
Nested classes inherited from class java.util.logging.LogManager
 
Field Summary
protected  java.util.Map classLoaderLoggers
          Map containing the classloader information, keyed per classloader.
protected  ObjectStore loggerRepository
          The ObjectStore is added to have an single, global ObjectStoreImpl.
protected  java.lang.ThreadLocal prefix
          This prefix is used to allow using prefixes for the properties names of handlers and their subcomponents.
 
Fields inherited from class java.util.logging.LogManager
 
Constructor Summary
ClassLoaderLogManager()
          Default Constructor.
 
Method Summary
 boolean addLogger(java.util.logging.Logger logger)
          Add the specified logger to the classloader local configuration.
protected  java.util.logging.Logger createRootLogger()
          Creates a new RootLogger.
protected static void doSetParentLogger(java.util.logging.Logger logger, java.util.logging.Logger parent)
          Set parent child relationship between the two specified loggers.
protected  ClassLoaderLogManager.ClassLoaderLogInfo getClassLoaderInfo(java.lang.ClassLoader classloader)
          Retrieve the configuration associated with the specified classloader.
 java.lang.String getFQCNofLogger()
          Returns the full qualified class name of the logger. Must correspond to getLoggerClass, but should not be created dynamicly.
 java.util.logging.Logger getLogger(java.lang.String name)
          Get the logger associated with the specified name inside the classloader local configuration.
 java.lang.Class getLoggerClass()
          Returns the class of the actual used logger for system.
 java.util.Enumeration getLoggerNames()
          Get an enumeration of the logger names currently defined in the classloader local configuration.
 ObjectStore getLoggerRepository()
          Get the actual repository for objects in the system.
 java.lang.String getProperty(java.lang.String name)
          Get the value of the specified property in the classloader local configuration.
 void readConfiguration()
          
protected  void readConfiguration(java.lang.ClassLoader classLoader)
          Read configuration for the specified classloader.
 void readConfiguration(java.io.InputStream is)
          
protected  void readConfiguration(java.io.InputStream is, java.lang.ClassLoader classLoader)
          Load specified configuration.
protected  java.lang.String replace(java.lang.String str)
          System property replacement in the given string.
 
Methods inherited from class java.util.logging.LogManager
addPropertyChangeListener, checkAccess, getLogManager, removePropertyChangeListener, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classLoaderLoggers

protected final java.util.Map classLoaderLoggers
Map containing the classloader information, keyed per classloader. A weak hashmap is used to ensure no classloader reference is leaked from application redeployment.


prefix

protected java.lang.ThreadLocal prefix
This prefix is used to allow using prefixes for the properties names of handlers and their subcomponents.


loggerRepository

protected ObjectStore loggerRepository
The ObjectStore is added to have an single, global ObjectStoreImpl. Later it might be a full implementation with throwing events on changes...

Constructor Detail

ClassLoaderLogManager

public ClassLoaderLogManager()
Default Constructor.

Method Detail

addLogger

public boolean addLogger(java.util.logging.Logger logger)
Add the specified logger to the classloader local configuration.

Parameters:
logger - The logger to be added.
Returns:
whether the logger had to be added (true) or not (false).

getLogger

public java.util.logging.Logger getLogger(java.lang.String name)
Get the logger associated with the specified name inside the classloader local configuration. If this returns null, and the call originated for Logger.getLogger, a new logger with the specified name will be instantiated and added using addLogger.

Parameters:
name - The name of the logger to retrieve.
Returns:
the logger corresponding to classloader and name.

getLoggerNames

public java.util.Enumeration getLoggerNames()
Get an enumeration of the logger names currently defined in the classloader local configuration.

Returns:
all logger names corresponding to the classloder.

getProperty

public java.lang.String getProperty(java.lang.String name)
Get the value of the specified property in the classloader local configuration.

Parameters:
name - The property name
Returns:
the property value or if not existing null.

readConfiguration

public void readConfiguration()
                       throws java.io.IOException,
                              java.lang.SecurityException

Throws:
java.io.IOException
java.lang.SecurityException
Since:
0.5

readConfiguration

public void readConfiguration(java.io.InputStream is)
                       throws java.io.IOException,
                              java.lang.SecurityException

Throws:
java.io.IOException
java.lang.SecurityException
Since:
0.5

getLoggerRepository

public ObjectStore getLoggerRepository()
Get the actual repository for objects in the system.

Specified by:
getLoggerRepository in interface LoggerRepositoryHolder
Returns:
the actual ObjectStore.
Since:
0.5

getFQCNofLogger

public java.lang.String getFQCNofLogger()
Returns the full qualified class name of the logger. Must correspond to getLoggerClass, but should not be created dynamicly.

Specified by:
getFQCNofLogger in interface LoggerClassInformation
Returns:
class name of the logger.
Since:
0.5

getLoggerClass

public java.lang.Class getLoggerClass()
Returns the class of the actual used logger for system.

Specified by:
getLoggerClass in interface LoggerClassInformation
Returns:
class of the logger.
Since:
0.5

getClassLoaderInfo

protected ClassLoaderLogManager.ClassLoaderLogInfo getClassLoaderInfo(java.lang.ClassLoader classloader)
Retrieve the configuration associated with the specified classloader. If it does not exist, it will be created.

Parameters:
classloader - The classloader for which we will retrieve or build the configuration
Returns:
the LogInfo for the given classLoader.

readConfiguration

protected void readConfiguration(java.lang.ClassLoader classLoader)
                          throws java.io.IOException
Read configuration for the specified classloader.

Parameters:
classLoader - to load the properties from.
Throws:
java.io.IOException - if reading the contained or derived logging.properties file fails.

readConfiguration

protected void readConfiguration(java.io.InputStream is,
                                 java.lang.ClassLoader classLoader)
                          throws java.io.IOException
Load specified configuration.

Parameters:
is - InputStream to the properties file
classLoader - for which the configuration will be loaded
Throws:
java.io.IOException - If something wrong happens during load.

doSetParentLogger

protected static void doSetParentLogger(java.util.logging.Logger logger,
                                        java.util.logging.Logger parent)
Set parent child relationship between the two specified loggers.

Parameters:
logger - the child logger.
parent - the new parent logger.

replace

protected java.lang.String replace(java.lang.String str)
System property replacement in the given string.

Parameters:
str - The original string
Returns:
the modified string

createRootLogger

protected java.util.logging.Logger createRootLogger()
Creates a new RootLogger. Intended to be overriden by subclasses with different Loggers.

Returns:
one new root logger.


${license_html}