Log4j 0.9.1

org.log4j
Class BasicConfigurator

java.lang.Object
  |
  +--org.log4j.BasicConfigurator
Direct Known Subclasses:
DOMConfigurator, PropertyConfigurator

public class BasicConfigurator
extends Object

Use this class to quickly configure the package.

For file based configuration see PropertyConfigurator. For XML based configuration see DOMConfigurator.

Since:
0.8.1
Author:
Ceki Gülcü

Field Summary
static String DISABLE_OVERRIDE_KEY
          Setting the system property log4j.disableOverride to "true" or any other value than "false" overrides the effects of all methods disable(org.log4j.Priority), disableAll(), disableDebug() and disableInfo().
static String INHERITED
          Special priority value signifying inherited behaviour.
 
Constructor Summary
protected BasicConfigurator()
           
 
Method Summary
static void configure()
          Add a FileAppender that uses PatternLayout using the PatternLayout.TTCC_CONVERSION_PATTERN and prints to System.out to the root category.
static void configure(Appender appender)
          Add appender to the root category.
static void disable(Priority p)
          Disable all logging requests of priority equal to or below the priority parameter p, regardless of the request category.
static void disableAll()
          Disable all logging requests regardless of category and priority.
static void disableDebug()
          Disable all logging requests of priority DEBUG regardless of category.
static void disableInfo()
          Disable all logging requests of priority INFO and below regardless of category.
static void enableAll()
          Undoes the effect of calling any of disable(org.log4j.Priority), disableAll(), disableDebug() and disableInfo() methods.
static void flagAsShippedCode()
          Deprecated.  
protected static void overrideAsNeeded(String override)
          Override the shipped code flag if the override parameter is not null.
static void resetConfiguration()
          Reset the configuration to its default.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISABLE_OVERRIDE_KEY

public static final String DISABLE_OVERRIDE_KEY
Setting the system property log4j.disableOverride to "true" or any other value than "false" overrides the effects of all methods disable(org.log4j.Priority), disableAll(), disableDebug() and disableInfo(). Thus, enabling normal evaluation of logging requests, i.e. according to the Basic Selection Rule.

DISABLE_OVERRIDE_KEY is the name of the constant holding the string value log4j.disableOverride.

Since:
0.8.5

INHERITED

public static final String INHERITED
Special priority value signifying inherited behaviour. The current value of this string constant is inherited.
Constructor Detail

BasicConfigurator

protected BasicConfigurator()
Method Detail

configure

public static void configure()
Add a FileAppender that uses PatternLayout using the PatternLayout.TTCC_CONVERSION_PATTERN and prints to System.out to the root category.

configure

public static void configure(Appender appender)
Add appender to the root category.
Parameters:
appender - The appender to add to the root category.

disable

public static void disable(Priority p)
Disable all logging requests of priority equal to or below the priority parameter p, regardless of the request category. Logging requests of higher priority then the priority of p remain unaffected.

Nevertheless, if the DISABLE_OVERRIDE_KEY system property is set to "true" or any value other than "false", then logging requests are evaluated as usual, i.e. according to the Basic Selection Rule.

The "disable" family of methods are there for speed. They allow printing methods such as debug, info, etc. to return immediately after an interger comparison without walking the category hierarchy. In most modern computers an integer comparison is measured in nanoseconds where as a category walk is measured in units of microseconds.

Other configurators define alternate ways of overriding the disable override flag. See PropertyConfigurator and DOMConfigurator.

Since:
0.8.5

disableAll

public static void disableAll()
Disable all logging requests regardless of category and priority. This method is equivalent to calling disable(org.log4j.Priority) with the argument Priority.EMERG, the highest possible priority.
Since:
0.8.5

disableDebug

public static void disableDebug()
Disable all logging requests of priority DEBUG regardless of category. Invoking this method is equivalent to calling disable(org.log4j.Priority) with the argument Priority.DEBUG.
Since:
0.8.5

disableInfo

public static void disableInfo()
Disable all logging requests of priority INFO and below regardless of category. Note that DEBUG messages are also disabled.

Invoking this method is equivalent to calling disable(org.log4j.Priority) with the argument Priority.INFO.

Since:
0.8.5

enableAll

public static void enableAll()
Undoes the effect of calling any of disable(org.log4j.Priority), disableAll(), disableDebug() and disableInfo() methods. More precisely, invoking this method sets the Category class internal variable called disable to its default "off" value.
Since:
0.8.5

flagAsShippedCode

public static void flagAsShippedCode()
Deprecated.  

This method is equivalent to the disableInfo() method.
Since:
0.8.0

overrideAsNeeded

protected static void overrideAsNeeded(String override)
Override the shipped code flag if the override parameter is not null.

If override is null then there is nothing to do. Otherwise, set Category.shippedCode to false if override has a value other than "false".


resetConfiguration

public static void resetConfiguration()
Reset the configuration to its default. This removes all appenders from all categories, sets the priority of all non-root categories to null, their additivity flad to true and sets the priority of the root category to DEBUG. Moreover, message disabling is set its default "off" value.

This method should be used sparingly and with care as it will block all logging until it is completed.

Since:
version 0.8.5

Log4j 0.9.1

Please notify me about new log4j releases.