it.andynaz.log
Class Config

java.lang.Object
  extended by it.andynaz.log.Config

public class Config
extends Object

Configuration of a Logger. A configuration can be used by various loggers.

Wrap alla the properties for a logger in a Properties object (different from the one it is constructed), such as the log level or if the date has to be shown.
Properties from the logger can be obtained using the getProperty(java.lang.String) method.

Each logger takes the properties it needs from the configuration on creation time. If a property is not found, it should use a default value. For the list of the values searched by each kind of logger, look at its documentation.

The class has also a shared config (can be thougth as a default one) used to create logger without a specified configuration. This configuration can be initialized using the vatious init() methods and can be retrived using the getConfig() method.

Version:
2013/01/14
Author:
andynaz

Constructor Summary
Config(Properties props)
          Creates a new configuration.
 
Method Summary
static Config getConfig()
          Returns the shared configuration.
 String getProperty(String propName)
          Get a property value.
static void init()
          Inizialize the shared configuration.
static void init(Properties props)
          Inizialize the shared configuration with a Properties object.
static void init(String file)
          Inizialize the shared configuration with a file of properties.
 void list()
          List all the properties on the standard output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Config

public Config(Properties props)
Creates a new configuration.

A config is constructed using a Properties object; it takes all the properties starting with "andyLog." and stores them in an internal Properties object, without the prefix (for instance, the property "andyLog.level" is stored as "level").

Parameters:
props - set of properties
Method Detail

getProperty

public String getProperty(String propName)
Get a property value.

Parameters:
propName - name of the property
Returns:
the value of the property, or null if the property is not found

init

public static void init(Properties props)
Inizialize the shared configuration with a Properties object.

This method can be inviked several times during execution; only the last configuration is saved.

Parameters:
props - properties to read

init

public static void init(String file)
Inizialize the shared configuration with a file of properties. If the file file is not found, the error is printed in the standard output.

This method can be inviked several times during execution; only the last configuration is saved.

Parameters:
file - path to the properties file

init

public static void init()
Inizialize the shared configuration. This method search for a file called "config.properties" in the curretn directory. If the file file is not found, the error is printed in the standard output.

This method can be inviked several times during execution; only the last configuration is saved.


getConfig

public static Config getConfig()
Returns the shared configuration. Should be used by the loggers created without configuration.

By default the object returned has an empty list of properties; to initialize the configuration use one of the init() methods.

Returns:
the shared configuration

list

public void list()
List all the properties on the standard output. Used only for debug pourpose.



(c) 2013 andynaz - http://andynaz.altervista.org