simtools.util
Class LogConfigurator

java.lang.Object
  extended by simtools.util.LogConfigurator
Direct Known Subclasses:
LogConfigurator

public class LogConfigurator
extends java.lang.Object


Field Summary
protected  java.util.ArrayList levels
          The various log levels read from the properties
protected  java.util.logging.Level lowestLevel
          The computed lowes level used to configure the handler
protected  java.util.logging.Handler outHandler
          The resulting configured handler It can be either the SocketHandler if a port number defintion is found or the the FileHandler if a pattern defintion is found or the ConsoleHandler
protected  java.util.ArrayList prefixes
          The various logger prefix read from the properties The level applied to each logger is contained at the same index in the levels list
protected  java.lang.String propertyPrefix
          The prefix used to compute property names
 
Constructor Summary
LogConfigurator(java.util.Properties p, java.lang.String prefix)
          Read the logging configuration
 
Method Summary
 void apply()
          Apply the logging configuration to the current loggers Can be called several times in case new classes are loaded
protected  void configure()
          Get logging configuration from properties and create the lgging handler accondingly
protected  void configureLevels()
          Configure logging levels according to properties
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Get a boolean value from properties
protected  java.lang.String getDefaultFileHandlerPattern()
           
protected  int getInt(java.lang.String key, int defaultValue)
          Get a int value from properties
static java.util.logging.Logger getLogger(java.lang.String name)
          Replace Loggger.getLogger call with this method in order to apply configuration to the new created loggers
protected  java.lang.String getPropertyName(java.lang.String key)
          Compute the property name according to the key parameter
protected  java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Get a String value from properties
static void setDefaultLowestLevel(java.util.logging.Level defaultLowestLevel)
          Method setDefaultLowestLevel
Summary:
Set the default lowest level of logs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertyPrefix

protected java.lang.String propertyPrefix
The prefix used to compute property names


outHandler

protected java.util.logging.Handler outHandler
The resulting configured handler It can be either the SocketHandler if a port number defintion is found or the the FileHandler if a pattern defintion is found or the ConsoleHandler


levels

protected java.util.ArrayList levels
The various log levels read from the properties


prefixes

protected java.util.ArrayList prefixes
The various logger prefix read from the properties The level applied to each logger is contained at the same index in the levels list


lowestLevel

protected java.util.logging.Level lowestLevel
The computed lowes level used to configure the handler

Constructor Detail

LogConfigurator

public LogConfigurator(java.util.Properties p,
                       java.lang.String prefix)
Read the logging configuration

Parameters:
p -
prefix -
Method Detail

getLogger

public static java.util.logging.Logger getLogger(java.lang.String name)
Replace Loggger.getLogger call with this method in order to apply configuration to the new created loggers

Parameters:
name - the logger name
Returns:
the new logger as returned by Logger.getLogger(name)

apply

public void apply()
Apply the logging configuration to the current loggers Can be called several times in case new classes are loaded


configure

protected void configure()
Get logging configuration from properties and create the lgging handler accondingly


configureLevels

protected void configureLevels()
Configure logging levels according to properties


getDefaultFileHandlerPattern

protected java.lang.String getDefaultFileHandlerPattern()
Returns:
the defaukt pattern to use by the FileHandler

getPropertyName

protected java.lang.String getPropertyName(java.lang.String key)
Compute the property name according to the key parameter

Parameters:
key - to compute the property name
Returns:
the property name

getString

protected java.lang.String getString(java.lang.String key,
                                     java.lang.String defaultValue)
Get a String value from properties

Parameters:
key - to compute the property name
defaultValue - the returned value if no property to define it
Returns:
the String value

getInt

protected int getInt(java.lang.String key,
                     int defaultValue)
Get a int value from properties

Parameters:
key - to compute the property name
defaultValue - the returned value if no property to define it
Returns:
the int value

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Get a boolean value from properties

Parameters:
key - to compute the property name
defaultValue - the returned value if no property to define it
Returns:
the value

setDefaultLowestLevel

public static void setDefaultLowestLevel(java.util.logging.Level defaultLowestLevel)
Method setDefaultLowestLevel
Summary:
Set the default lowest level of logs. This level will be used if no configuration is available.

Parameters:
defaultLowestLevel - the defaultLowestLevel to set. Level.SEVERE/WARNING etc..