logahawk
Class HashLoggerRegistry

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

@ThreadSafe
public class HashLoggerRegistry
extends Object
implements LoggerRegistry

A map based implementation of LoggerRegistry. Loggers must be registered by keys prior to being retrieved. The look up of key to find Logger is exact -- does not perform partial matching of the key. (See HierarchicalLoggerRegistry for such functionality.) This class previously called simply "LoggerRegistry", before the creation of the interface with the same name.


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
HashLoggerRegistry(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 key)
          Returns the Logger previously registered with the provided key via put(String, Logger).
 Enumeration<String> getKeys()
          Returns the keys of all registered Loggers.
 Logger getRootLogger()
          Returns the root (or default) Logger.
 void put(String key, Logger logger)
          Registers a Logger for the provided key.
 void remove(String key)
          Remove a Logger registered under the provided key.
 
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

HashLoggerRegistry

public HashLoggerRegistry(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 key)
Returns the Logger previously registered with the provided key via put(String, Logger). The look up is exact -- does not perform partial matches.

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 key,
                Logger logger)
Registers a Logger for the provided key.

Parameters:
key - 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 key)
Remove a Logger registered under the provided key.