Log4j 1.3alpha-8

org.apache.log4j.helpers
Class LoggerTraverse

java.lang.Object
  |
  +--org.apache.log4j.helpers.LoggerTraverse

public class LoggerTraverse
extends Object

This helper class can be used to extract/traverse logger information for a given LoggerRepository. It is a work in progress and focus to date has been functionality, not performance or efficiency. The set of loggers can be retrieved in one of two ways: 1) getLoggerNames() - A complete list of the loggers 2) getLoggerPackageNames() - A list of package names, starting at a given package name pattern. If the second retrieval method is used, the caller can iteratively call the LoggerTraverse to retrieve sub-packages and children. This class is dependent on logger names that match Java fully qualified class names. It also provides methods for querying the current level of a given logger and NOTE: This class does not cause any side effects in the LoggerRepository. It does not inadvertantly create new Loggers in the process of parsing the package names or accessing information. NOTE: This class does not automatically keep track of changes in the given LoggerRepository. The caller must call the update() method to get the current set of loggers.

Author:
Mark Womack

Constructor Summary
LoggerTraverse()
          Empty constructor.
LoggerTraverse(LoggerRepository repository)
           
 
Method Summary
 Level getLevelForPackage(String packageName)
          Returns the effective level for the given package name.
 Level getLevelForRootLogger()
          Returns the level for the root logger.
 boolean getLevelIsSetForPackage(String packageName)
          Returns true of the package has had its level set directly or false if the level is inherited.
 List getLoggerNames()
          Returns the list of all loggers, sorted by name.
 List getLoggerPackageNames(String startPattern)
          Using a starting name pattern, returns the next level of package names that start with that pattern.
 boolean loggerHasSubPackages(String startPattern)
          Returns true if the given package name appears to have sub-package.
static void main(String[] args)
          here is an example of using the hierarchical version, iterating through all the package names, all the loggers.
 void update(LoggerRepository repository)
          Updates the LoggerTraverse to the current information in the given LoggerRepository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggerTraverse

public LoggerTraverse()
Empty constructor.

LoggerTraverse

public LoggerTraverse(LoggerRepository repository)
Parameters:
repository - The LoggerRepository to traverse.
Method Detail

update

public void update(LoggerRepository repository)
Updates the LoggerTraverse to the current information in the given LoggerRepository.
Parameters:
repository - LoggerRepository to use for Logger information.

getLoggerNames

public List getLoggerNames()
Returns the list of all loggers, sorted by name.
Returns:
List List of the current loggers.

getLoggerPackageNames

public List getLoggerPackageNames(String startPattern)
Using a starting name pattern, returns the next level of package names that start with that pattern. Returns a list, as there can be more than one return value. Passing in an empty string for the starting pattern will return a list of the top level package names. For example, if the following logger names were defined: org.apache.log4j and org.apache.log4j-extensions, then passing in an empty string would return one item in the list with a value of "org". If the pattern "org.apache" were passed in, then the list would contain two items, "log4j" and "log4j-extensions".
Parameters:
startPattern - The name pattern to match for Logger name.
Returns:
List List of matching Logger names that start with the pattern.

loggerHasSubPackages

public boolean loggerHasSubPackages(String startPattern)
Returns true if the given package name appears to have sub-package.
Parameters:
startPattern - The name pattern to match for Logger name.
Returns:
boolean True if there are existing loggers that match.

getLevelForRootLogger

public Level getLevelForRootLogger()
Returns the level for the root logger.
Returns:
Level The current Level for the root logger.

getLevelForPackage

public Level getLevelForPackage(String packageName)
Returns the effective level for the given package name. If no level is set for the given package, then search back through the package names until one is found that is set or return the level of the root logger.
Parameters:
packageName - The name of the logger to return the level for.
Returns:
Level The level of the logger.

getLevelIsSetForPackage

public boolean getLevelIsSetForPackage(String packageName)
Returns true of the package has had its level set directly or false if the level is inherited.
Parameters:
packageName - The name of the logger to return the level for.
Returns:
boolean True if the level has been explicitly configured.

main

public static void main(String[] args)
here is an example of using the hierarchical version, iterating through all the package names, all the loggers.
Parameters:
args - Parameters for main execution.

Log4j 1.3alpha-8

Copyright © 2000-2006 Apache Software Foundation.
Licensed under the Apache License, Version 2.0.