logahawk
Class HierarchicalLoggerRegistry

java.lang.Object
  extended by logahawk.HierarchicalLoggerRegistry
All Implemented Interfaces:
LoggerRegistry

public class HierarchicalLoggerRegistry
extends Object
implements LoggerRegistry

A hierarchical based implementation of LoggerRegistry. Loggers must be registered by package name being retrieved. The look up of key to find Logger is not exact See HashLoggerRegistry for such functionality.


Field Summary
protected  ConcurrentHashMap<String,Logger> loggerMap
          Map from keys to Logger.
protected  Logger rootLogger
          The default Logger used when failing to find a Logger in the loggerMap.
 
Constructor Summary
HierarchicalLoggerRegistry(Logger rootLogger)
           
 
Method Summary
 void clear()
          Removes all registered Loggers.
 Logger get(Class clazz)
          Returns the Logger using Class.getName() as an argument to get(String).
 Logger get(String path)
          Returns the Logger for the provided class path.
 Enumeration<String> getKeys()
          Returns the keys of all registered Loggers.
protected  String getParentPath(String path)
          Returns a more general (or more "root") path from the given path.
 Logger getRootLogger()
          Returns the root (or default) Logger.
 void put(String path, Logger logger)
          Registers a Logger for the provided class path.
 void remove(String path)
          Remove a Logger registered under the provided path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootLogger

protected Logger rootLogger
The default Logger used when failing to find a Logger in the loggerMap.


loggerMap

protected final ConcurrentHashMap<String,Logger> loggerMap
Map from keys to Logger. A Logger can be registered under multiple keys.

Constructor Detail

HierarchicalLoggerRegistry

public HierarchicalLoggerRegistry(Logger rootLogger)
Method Detail

getRootLogger

public Logger getRootLogger()
Description copied from interface: LoggerRegistry
Returns the root (or default) Logger. The default is used when no Logger matches (String) .

Specified by:
getRootLogger in interface LoggerRegistry

get

public Logger get(String path)
Returns the Logger for the provided class path. This first attempts an exact match on the full class name, and failing that it works its way up the package path looking for the next best fit.

Specified by:
get in interface LoggerRegistry

get

public Logger get(Class clazz)
Returns the Logger using Class.getName() as an argument to get(String).

Specified by:
get in interface LoggerRegistry

getKeys

public Enumeration<String> getKeys()
Returns the keys of all registered Loggers.


put

public void put(String path,
                Logger logger)
Registers a Logger for the provided class path.

Parameters:
path - The path to register Logger. This can be a package path or a specific Class.getName(). This cannot be null or the empty string -- that corresponds to the rootLogger.

clear

public void clear()
Removes all registered Loggers.


remove

public void remove(String path)
Remove a Logger registered under the provided path.


getParentPath

protected String getParentPath(String path)
Returns a more general (or more "root") path from the given path. For example if the path provided is "cat.dog .bird" this returns "cat.dog". This returns null if the provided path is one package deep (e.g. "cat"), which signals that the rootLogger should likely be used.