You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2001/09/04 20:44:48 UTC
cvs commit: jakarta-log4j/src/java/org/apache/log4j/xml/test SubClassTest.java XTest.java
ceki 01/09/04 11:44:48
Modified: src/java/org/apache/log4j Category.java
DefaultCategoryFactory.java Hierarchy.java
Level.java Logger.java Priority.java
src/java/org/apache/log4j/examples Makefile MyCategory.java
src/java/org/apache/log4j/net SocketNode.java
src/java/org/apache/log4j/spi HierarchyEventListener.java
LoggerRepository.java LoggingEvent.java
RootCategory.java
src/java/org/apache/log4j/test CustomCategoryTest.java
FQCNTest.java Makefile SocketAppenderTest.java
UnitTestLogger.java
src/java/org/apache/log4j/xml DOMConfigurator.java Makefile
src/java/org/apache/log4j/xml/examples Makefile XTest.java
src/java/org/apache/log4j/xml/test SubClassTest.java
XTest.java
Log:
Logger now extends Category. This way of doing things ensure backwards compatibility.
Revision Changes Path
1.46 +884 -20 jakarta-log4j/src/java/org/apache/log4j/Category.java
Index: Category.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Category.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- Category.java 2001/09/04 14:53:12 1.45
+++ Category.java 2001/09/04 18:44:47 1.46
@@ -52,12 +52,169 @@
@author Ceki Gülcü
@author Anders Kristensen */
-public class Category extends Logger implements AppenderAttachable {
+public class Category implements AppenderAttachable {
+ /**
+ The hierarchy where categories are attached to by default.
+ */
+ static
+ public
+ final Hierarchy defaultHierarchy = new Hierarchy(new
+ RootCategory(Level.DEBUG));
+
+
+ /**
+ This string constant is set to <b>log4j.properties</b> the name
+ of the file that will be searched by default in classpath. If the
+ file can be found, then it is fed to the {@link
+ PropertyConfigurator}.
+
+ See also {@link #DEFAULT_CONFIGURATION_KEY} for a more general
+ alternative.
+
+ <p>See also the full description of <a
+ href="../../../../manual.html#defaultInit">default
+ intialization</a> procedure.
+
+ @since 0.8.5 */
+ static public final String DEFAULT_CONFIGURATION_FILE = "log4j.properties";
+
+ /**
+ This string constant is set to <b>log4j.configuration</b>.
+
+ <p>It corresponds to name of a system property that, if set,
+ specifies the name of the resource containing the properties file
+ or {@link URL} with which log4j should configure itself. See
+ {@link OptionConverter#selectAndConfigure} for more detailed
+ information on the processing of this option.
+
+ <p>Setting the <b>log4j.configuration</b> system property
+ overrides the default search for the file <b>log4j.properties</b>.
+
+ <p>Note that all property keys are case sensitive.
+
+ <p>See also the full description of <a
+ href="../../../../manual.html#defaultInit">default
+ intialization</a> procedure.
+
+ @since 1.0 */
+ static final public String DEFAULT_CONFIGURATION_KEY="log4j.configuration";
+
+ /**
+ This string constant is set to <b>log4j.configuratorClass</b>.
+
+ <p>It corresponds to name of a system property that, if set,
+ specifies the class name to use to automatically configure
+ log4j. See {@link OptionConverter#selectAndConfigure} for more
+ detailed information on the processing of this option.
+
+ <p>Setting the <b>log4j.configuration</b> system property
+ overrides the default search for the file <b>log4j.properties</b>.
+
+ <p>Note that all property keys are case sensitive.
+
+ <p>See also the full description of <a
+ href="../../../../manual.html#defaultInit">default
+ intialization</a> procedure.
+
+ @since 1.2 */
+ static final public String CONFIGURATOR_CLASS_KEY="log4j.configuratorClass";
+
+ /**
+ Setting the system property <b>log4j.defaultInitOverride</b> to
+ "true" or any other value than "false" will skip default
+ configuration process.
+
+ <p>The current value of the DEFAULT_INIT_OVERRIDE_KEY string
+ constant is <b>log4j.defaultInitOverride</b>.
+
+ <p>See also the full description of <a
+ href="../../../../manual.html#defaultInit">default
+ intialization</a> procedure.
+
+ <p>Note that all property keys are case sensitive.
+
+ @since 0.8.5 */
+ public static final String DEFAULT_INIT_OVERRIDE_KEY =
+ "log4j.defaultInitOverride";
+
+ /** Search for the properties file log4j.properties in the CLASSPATH. */
+ static {
+
+ String override =OptionConverter.getSystemProperty(DEFAULT_INIT_OVERRIDE_KEY,
+ null);
+
+ // if there is no default init override, them get the resource
+ // specified by the user or the default config file.
+ if(override == null || "false".equalsIgnoreCase(override)) {
+ String resource = OptionConverter.getSystemProperty(
+ DEFAULT_CONFIGURATION_KEY,
+ DEFAULT_CONFIGURATION_FILE);
+
+ String configuratorClassName = OptionConverter.getSystemProperty(
+ CONFIGURATOR_CLASS_KEY,
+ null);
+
+ URL url = null;
+ try {
+ // so, resource is not a URL:
+ // attempt to get the resource from the class path
+ url = new URL(resource);
+ } catch (MalformedURLException ex) {
+ url = Loader.getResource(resource);
+ }
+
+ // If we have a non-null url, then delegate the rest of the
+ // configuration to the OptionConverter.selectAndConfigure
+ // method.
+ if(url != null) {
+ LogLog.debug("Using URL ["+url+"] for automatic log4j configuration.");
+ OptionConverter.selectAndConfigure(url, configuratorClassName,
+ defaultHierarchy);
+ } else {
+ LogLog.debug("Could not find resource: ["+resource+"].");
+ }
+ }
+ }
+
+ /**
+ The name of this category.
+ */
+ protected String name;
+
+ /**
+ The assigned level of this category. The
+ <code>level</code> variable need not be assigned a value in
+ which case it is inherited form the hierarchy. */
+ volatile protected Level level;
+
+ /**
+ The parent of this category. All categories have at least one
+ ancestor which is the root category. */
+ volatile protected Category parent;
+
+ /**
+ The fully qualified name of the Category class. See also the
+ getFQCN method. */
private static final String FQCN = Category.class.getName();
+
+ protected ResourceBundle resourceBundle;
+
+ // Categories need to know what Hierarchy they are in
+ protected Hierarchy hierarchy;
- private static LoggerFactory factory = new DefaultCategoryFactory();
-
+
+ AppenderAttachableImpl aai;
+
+ /** Additivity is set to true by default, that is children inherit
+ the appenders of their ancestors by default. If this variable is
+ set to <code>false</code> then the appenders found in the
+ ancestors of this category are not used. However, the children
+ of this category will inherit its appenders, unless the children
+ have their additivity flag set to <code>false</code> too. See
+ the user manual for more details. */
+ protected boolean additive = true;
+
/**
This constructor created a new <code>Category</code> instance and
sets its name.
@@ -69,9 +226,98 @@
*/
protected
Category(String name) {
- super(name);
+ this.name = name;
+ }
+
+ /**
+ Add <code>newAppender</code> to the list of appenders of this
+ Category instance.
+
+ <p>If <code>newAppender</code> is already in the list of
+ appenders, then it won't be added again.
+ */
+ synchronized
+ public
+ void addAppender(Appender newAppender) {
+ if(aai == null) {
+ aai = new AppenderAttachableImpl();
+ }
+ aai.addAppender(newAppender);
+ hierarchy.fireAddAppenderEvent(this, newAppender);
+ }
+
+ /**
+ If <code>assertion</code> parameter is <code>false</code>, then
+ logs <code>msg</code> as an {@link #error(Object) error} statement.
+
+ <p>The <code>assert</code> method has been renamed to
+ <code>assertLog</code> because <code>assert</code> is a language
+ reserved word in JDK 1.4.
+
+ @param assertion
+ @param msg The message to print if <code>assertion</code> is
+ false.
+
+ @since 1.2 */
+ public
+ void assertLog(boolean assertion, String msg) {
+ if(!assertion)
+ this.error(msg);
+ }
+
+
+ /**
+ Call the appenders in the hierrachy starting at
+ <code>this</code>. If no appenders could be found, emit a
+ warning.
+
+ <p>This method calls all the appenders inherited from the
+ hierarchy circumventing any evaluation of whether to log or not
+ to log the particular log request.
+
+ @param LoggingEvent the event to log. */
+ public
+ void callAppenders(LoggingEvent event) {
+ int writes = 0;
+
+ for(Category c = this; c != null; c=c.parent) {
+ // Protected against simultaneous call to addAppender, removeAppender,...
+ synchronized(c) {
+ if(c.aai != null) {
+ writes += c.aai.appendLoopOnAppenders(event);
+ }
+ if(!c.additive) {
+ break;
+ }
+ }
+ }
+ // No appenders in hierarchy, warn user only once.
+ if(!hierarchy.emittedNoAppenderWarning && writes == 0) {
+ LogLog.error("No appenders could be found for category (" +
+ this.getName() + ").");
+ LogLog.error("Please initialize the log4j system properly.");
+ hierarchy.emittedNoAppenderWarning = true;
+ }
}
+ /**
+ Close all attached appenders implementing the AppenderAttachable
+ interface.
+ @since 1.0
+ */
+ synchronized
+ void closeNestedAppenders() {
+ Enumeration enum = this.getAllAppenders();
+ if(enum != null) {
+ while(enum.hasMoreElements()) {
+ Appender a = (Appender) enum.nextElement();
+ if(a instanceof AppenderAttachable) {
+ a.close();
+ }
+ }
+ }
+ }
+
/**
Log a message object with the {@link Level#DEBUG DEBUG} level.
@@ -152,14 +398,151 @@
forcedLog(FQCN, Level.ERROR, message, null);
}
+ /**
+ Log a message object with the <code>ERROR</code> level including
+ the stack trace of the {@link Throwable} <code>t</code> passed as
+ parameter.
+
+ <p>See {@link #error(Object)} form for more detailed information.
+
+ @param message the message object to log.
+ @param t the exception to log, including its stack trace. */
+ public
+ void error(Object message, Throwable t) {
+ if(hierarchy.enableInt > Level.ERROR_INT)
+ return;
+ if(Level.ERROR.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, Level.ERROR, message, t);
+
+ }
+
+
+ /**
+ If the named category exists (in the default hierarchy) then it
+ returns a reference to the category, otherwise it returns
+ <code>null</code>.
+
+ <p>Contributed by Ciaran Treanor - ciaran@xelector.com
+ @version 0.8.5 */
+ public
+ static
+ Logger exists(String name) {
+ return defaultHierarchy.exists(name);
+ }
+
+ /**
+ Log a message object with the {@link Level#FATAL FATAL} Level.
+
+ <p>This method first checks if this category is <code>FATAL</code>
+ enabled by comparing the level of this category with {@link
+ Level#FATAL FATAL} Level. If the category is <code>FATAL</code>
+ enabled, then it converts the message object passed as parameter
+ to a string by invoking the appropriate {@link ObjectRenderer}. It
+ proceeds to call all the registered appenders in this category and
+ also higher in the hierarchy depending on the value of the
+ additivity flag.
+
+ <p><b>WARNING</b> Note that passing a {@link Throwable} to this
+ method will print the name of the Throwable but no stack trace. To
+ print a stack trace use the {@link #fatal(Object, Throwable)} form
+ instead.
+
+ @param message the message object to log */
+ public
+ void fatal(Object message) {
+ if(hierarchy.enableInt > Level.FATAL_INT)
+ return;
+ if(Level.FATAL.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, Level.FATAL, message, null);
+ }
+
+ /**
+ Log a message object with the <code>FATAL</code> level including
+ the stack trace of the {@link Throwable} <code>t</code> passed as
+ parameter.
+
+ <p>See {@link #fatal(Object)} for more detailed information.
+
+ @param message the message object to log.
+ @param t the exception to log, including its stack trace. */
+ public
+ void fatal(Object message, Throwable t) {
+ if(hierarchy.enableInt > Level.FATAL_INT)
+ return;
+ if(Level.FATAL.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, Level.FATAL, message, t);
+ }
+
+
+ /**
+ This method creates a new logging event and logs the event
+ without further checks. */
+ protected
+ void forcedLog(String fqcn, Level level, Object message, Throwable t) {
+ callAppenders(new LoggingEvent(fqcn, this, level, message, t));
+ }
+
+
+ /**
+ Get the additivity flag for this Category instance.
+ */
+ public
+ boolean getAdditivity() {
+ return additive;
+ }
+
+ /**
+ Get the appenders contained in this category as an {@link
+ Enumeration}. If no appenders can be found, then a {@link NullEnumeration}
+ is returned.
+
+ @return Enumeration An enumeration of the appenders in this category. */
+ synchronized
+ public
+ Enumeration getAllAppenders() {
+ if(aai == null)
+ return NullEnumeration.getInstance();
+ else
+ return aai.getAllAppenders();
+ }
+
/**
+ Look for the appender named as <code>name</code>.
+
+ <p>Return the appender with that name if in the list. Return
+ <code>null</code> otherwise. */
+ synchronized
+ public
+ Appender getAppender(String name) {
+ if(aai == null || name == null)
+ return null;
+
+ return aai.getAppender(name);
+ }
+
+ /**
+ Starting from this category, search the category hierarchy for a
+ non-null level and return it. Otherwise, return the level of the
+ root category.
+
+ <p>The Category class is designed so that this method executes as
+ quickly as possible.
+ */
+ public
+ Level getChainedLevel() {
+ for(Category c = this; c != null; c=c.parent) {
+ if(c.level != null)
+ return c.level;
+ }
+ return null; // If reached will cause an NullPointerException.
+ }
+
+ /**
Returns all the currently defined categories in the default
hierarchy as an {@link java.util.Enumeration Enumeration}.
<p>The root category is <em>not</em> included in the returned
{@link Enumeration}.
-
- @deprecated FIXME FIXME FIXME FIXME FIXME FIXME FIXME
*/
public
static
@@ -168,6 +551,29 @@
}
+ /**
+ Return the default Hierarchy instance.
+
+ @since 1.0
+ */
+ public
+ static
+ Hierarchy getDefaultHierarchy() {
+ return defaultHierarchy;
+ }
+
+
+ /**
+ Return the the {@link Hierarchy} where this <code>Category</code> instance is
+ attached.
+
+ @since 1.1 */
+ public
+ Hierarchy getHierarchy() {
+ return hierarchy;
+ }
+
+
/**
Retrieve a category with named as the <code>name</code>
parameter. If the named category already exists, then the
@@ -177,15 +583,12 @@
By default, categories do not have a set level but inherit
it from the hierarchy. This is one of the central features of
log4j.
-
- @param name The name of the category to retrieve.
-
- */
+ @param name The name of the category to retrieve. */
public
static
- Category getInstance(String name) {
- return (Category) defaultHierarchy.getLogger(name, factory);
+ Logger getInstance(String name) {
+ return defaultHierarchy.getLogger(name);
}
/**
@@ -198,7 +601,7 @@
@since 1.0 */
public
static
- Category getInstance(Class clazz) {
+ Logger getInstance(Class clazz) {
return getInstance(clazz.getName());
}
@@ -219,29 +622,490 @@
@since 0.8.5 */
public
static
- Category getInstance(String name, LoggerFactory factory) {
- return (Category) defaultHierarchy.getLogger(name, factory);
+ Logger getInstance(String name, LoggerFactory factory) {
+ return defaultHierarchy.getLogger(name, factory);
}
+
+ /**
+ Return the category name. */
+ public
+ final
+ String getName() {
+ return name;
+ }
+
+
+ /**
+ Returns the parent of this category. Note that the parent of a
+ given category may change during the lifetime of the category.
+
+ <p>The root category will return <code>null</code>.
+
+ @since 1.2
+ */
+ final
+ public
+ Category getParent() {
+ return this.parent;
+ }
+
+
+ /**
+ Returns the assigned {@link Level}, if any, for this Category.
+
+ @return Level - the assigned Level, can be <code>null</code>.
+ */
+ final
+ public
+ Level getLevel() {
+ return this.level;
+ }
+
+ /**
+ @deprecated Please use {@link #getLevel} instead.
+ */
+ final
+ public
+ Level getPriority() {
+ return this.level;
+ }
+
+
+ /**
+ Return the root of the default category hierrachy.
+ <p>The root category is always instantiated and available. It's
+ name is "root".
+
+ <p>Nevertheless, calling {@link #getInstance
+ Category.getInstance("root")} does not retrieve the root category
+ but a category just under root named "root".
+
+ */
+ final
public
static
- Category getRoot() {
- return (Category) defaultHierarchy.getRootLogger();
+ Logger getRoot() {
+ return defaultHierarchy.getRootLogger();
+ }
+
+ /**
+ Return the <em>inherited</em> {@link ResourceBundle} for this
+ category.
+
+ <p>This method walks the hierarchy to find the appropriate
+ resource bundle. It will return the resource bundle attached to
+ the closest ancestor of this category, much like the way
+ priorities are searched. In case there is no bundle in the
+ hierarchy then <code>null</code> is returned.
+
+ @since 0.9.0 */
+ public
+ ResourceBundle getResourceBundle() {
+ for(Category c = this; c != null; c=c.parent) {
+ if(c.resourceBundle != null)
+ return c.resourceBundle;
+ }
+ // It might be the case that there is no resource bundle
+ return null;
+ }
+
+ /**
+ Returns the string resource coresponding to <code>key</code> in
+ this category's inherited resource bundle. See also {@link
+ #getResourceBundle}.
+
+ <p>If the resource cannot be found, then an {@link #error error}
+ message will be logged complaining about the missing resource.
+ */
+ protected
+ String getResourceBundleString(String key) {
+ ResourceBundle rb = getResourceBundle();
+ // This is one of the rare cases where we can use logging in order
+ // to report errors from within log4j.
+ if(rb == null) {
+ if(!hierarchy.emittedNoResourceBundleWarning) {
+ error("No resource bundle has been set for category "+name);
+ hierarchy.emittedNoResourceBundleWarning = true;
+ }
+ return null;
+ }
+ else {
+ try {
+ return rb.getString(key);
+ }
+ catch(MissingResourceException mre) {
+ error("No resource is associated with key \""+key+"\".");
+ return null;
+ }
+ }
+ }
+
+ /**
+ Log a message object with the {@link Level#INFO INFO} Level.
+
+ <p>This method first checks if this category is <code>INFO</code>
+ enabled by comparing the level of this category with {@link
+ Level#INFO INFO} Level. If the category is <code>INFO</code>
+ enabled, then it converts the message object passed as parameter
+ to a string by invoking the appropriate {@link ObjectRenderer}. It
+ proceeds to call all the registered appenders in this category and
+ also higher in the hierarchy depending on the value of the
+ additivity flag.
+
+ <p><b>WARNING</b> Note that passing a {@link Throwable} to this
+ method will print the name of the Throwable but no stack trace. To
+ print a stack trace use the {@link #info(Object, Throwable)} form
+ instead.
+
+ @param message the message object to log */
+ public
+ void info(Object message) {
+ if(hierarchy.enableInt > Level.INFO_INT)
+ return;
+ if(Level.INFO.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, Level.INFO, message, null);
+ }
+
+ /**
+ Log a message object with the <code>INFO</code> level including
+ the stack trace of the {@link Throwable} <code>t</code> passed as
+ parameter.
+
+ <p>See {@link #info(Object)} for more detailed information.
+
+ @param message the message object to log.
+ @param t the exception to log, including its stack trace. */
+ public
+ void info(Object message, Throwable t) {
+ if(hierarchy.enableInt > Level.INFO_INT)
+ return;
+ if(Level.INFO.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, Level.INFO, message, t);
+ }
+
+ /**
+ * Check whether this category is enabled for the <code>DEBUG</code>
+ * Level.
+ *
+ * <p> This function is intended to lessen the computational cost of
+ * disabled log debug statements.
+ *
+ * <p> For some <code>cat</code> Category object, when you write,
+ * <pre>
+ * cat.debug("This is entry number: " + i );
+ * </pre>
+ *
+ * <p>You incur the cost constructing the message, concatenatiion in
+ * this case, regardless of whether the message is logged or not.
+ *
+ * <p>If you are worried about speed, then you should write
+ * <pre>
+ * if(cat.isDebugEnabled()) {
+ * cat.debug("This is entry number: " + i );
+ * }
+ * </pre>
+ *
+ * <p>This way you will not incur the cost of parameter
+ * construction if debugging is disabled for <code>cat</code>. On
+ * the other hand, if the <code>cat</code> is debug enabled, you
+ * will incur the cost of evaluating whether the category is debug
+ * enabled twice. Once in <code>isDebugEnabled</code> and once in
+ * the <code>debug</code>. This is an insignificant overhead
+ * since evaluating a category takes about 1%% of the time it
+ * takes to actually log.
+ *
+ * @return boolean - <code>true</code> if this category is debug
+ * enabled, <code>false</code> otherwise.
+ * */
+ public
+ boolean isDebugEnabled() {
+ if(hierarchy.enableInt > Level.DEBUG_INT)
+ return false;
+ return Level.DEBUG.isGreaterOrEqual(this.getChainedLevel());
+ }
+
+ /**
+ Check whether this category is enabled for a given {@link
+ Level} passed as parameter.
+
+ See also {@link #isDebugEnabled}.
+
+ @return boolean True if this category is enabled for <code>level</code>.
+ */
+ public
+ boolean isEnabledFor(Level level) {
+ if(hierarchy.enableInt > level.level)
+ return false;
+ return level.isGreaterOrEqual(this.getChainedLevel());
+ }
+
+ /**
+ Check whether this category is enabled for the info Level.
+ See also {@link #isDebugEnabled}.
+
+ @return boolean - <code>true</code> if this category is enabled
+ for level info, <code>false</code> otherwise.
+ */
+ public
+ boolean isInfoEnabled() {
+ if(hierarchy.enableInt > Level.INFO_INT)
+ return false;
+ return Level.INFO.isGreaterOrEqual(this.getChainedLevel());
}
+
/**
+ Log a localized message. The user supplied parameter
+ <code>key</code> is replaced by its localized version from the
+ resource bundle.
+
+ @see #setResourceBundle
+
+ @since 0.8.4 */
+ public
+ void l7dlog(Level level, String key, Throwable t) {
+ if(hierarchy.enableInt > level.level) {
+ return;
+ }
+ if(level.isGreaterOrEqual(this.getChainedLevel())) {
+ String msg = getResourceBundleString(key);
+ // if message corresponding to 'key' could not be found in the
+ // resource bundle, then default to 'key'.
+ if(msg == null) {
+ msg = key;
+ }
+ forcedLog(FQCN, level, msg, t);
+ }
+ }
+ /**
+ Log a localized and parameterized message. First, the user
+ supplied <code>key</code> is searched in the resource
+ bundle. Next, the resulting pattern is formatted using
+ {@link MessageFormat#format(String,Object[])} method with the user
+ supplied object array <code>params</code>.
+
+ @since 0.8.4
+ */
+ public
+ void l7dlog(Level level, String key, Object[] params, Throwable t) {
+ if(hierarchy.enableInt > level.level) {
+ return;
+ }
+ if(level.isGreaterOrEqual(this.getChainedLevel())) {
+ String pattern = getResourceBundleString(key);
+ String msg;
+ if(pattern == null)
+ msg = key;
+ else
+ msg = java.text.MessageFormat.format(pattern, params);
+ forcedLog(FQCN, level, msg, t);
+ }
+ }
+
+ /**
+ This generic form is intended to be used by wrappers.
+ */
+ public
+ void log(Level level, Object message, Throwable t) {
+ if(hierarchy.enableInt > level.level) {
+ return;
+ }
+ if(level.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, level, message, t);
+ }
+
+ /**
+ This generic form is intended to be used by wrappers.
+ */
+ public
+ void log(Level level, Object message) {
+ if(hierarchy.enableInt > level.level) {
+ return;
+ }
+ if(level.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, level, message, null);
+ }
+
+ /**
+
+ This is the most generic printing method. It is intended to be
+ invoked by <b>wrapper</b> classes.
+
+ @param callerFQCN The wrapper class' fully qualified class name.
+ @param level The level of the logging request.
+ @param message The message of the logging request.
+ @param t The throwable of the logging request, may be null. */
+ public
+ void log(String callerFQCN, Level level, Object message, Throwable t) {
+ if(hierarchy.enableInt > level.level) {
+ return;
+ }
+ if(level.isGreaterOrEqual(this.getChainedLevel())) {
+ forcedLog(callerFQCN, level, message, t);
+ }
+ }
+
+
+ /**
+ Remove all previously added appenders from this Category
+ instance.
+
+ <p>This is useful when re-reading configuration information.
+ */
+ synchronized
+ public
+ void removeAllAppenders() {
+ if(aai != null) {
+ aai.removeAllAppenders();
+ aai = null;
+ }
+ }
+
+ /**
+ Remove the appender passed as parameter form the list of appenders.
+
+ @since 0.8.2
+ */
+ synchronized
+ public
+ void removeAppender(Appender appender) {
+ if(appender == null || aai == null)
+ return;
+ aai.removeAppender(appender);
+ }
+
+ /**
+ Remove the appender with the name passed as parameter form the
+ list of appenders.
+
+ @since 0.8.2 */
+ synchronized
+ public
+ void removeAppender(String name) {
+ if(name == null || aai == null) return;
+ aai.removeAppender(name);
+ }
+
+ /**
+ Set the additivity flag for this Category instance.
+ @since 0.8.1
+ */
+ public
+ void setAdditivity(boolean additive) {
+ this.additive = additive;
+ }
+
+ /**
+ Only the Hiearchy class can set the hiearchy of a
+ category. Default package access is MANDATORY here. */
+ final
+ void setHierarchy(Hierarchy hierarchy) {
+ this.hierarchy = hierarchy;
+ }
+
+ /**
+ Set the level of this Category.
+
+ <p>Null values are admitted.
+ */
+ public
+ void setLevel(Level level) {
+ this.level = level;
+ }
+
+
+ /**
Set the level of this Category.
<p>Null values are admitted.
- @deprecated Please use {@link Logger#setLevel} instead.
+ @deprecated Please use {@link #setLevel} instead.
*/
public
- void setPriority(Level level) {
- setLevel(level);
+ void setPriority(Level priority) {
+ this.level = priority;
}
+ /**
+ Set the resource bundle to be used with localized logging
+ methods {@link #l7dlog(Level,String,Throwable)} and {@link
+ #l7dlog(Level,String,Object[],Throwable)}.
+
+ @since 0.8.4
+ */
+ public
+ void setResourceBundle(ResourceBundle bundle) {
+ resourceBundle = bundle;
+ }
+
+ /**
+ Calling this method will <em>safely</em> close and remove all
+ appenders in all the categories including root contained in the
+ default hierachy.
+
+ <p>Some appenders such as {@link org.apache.log4j.net.SocketAppender}
+ and {@link AsyncAppender} need to be closed before the
+ application exists. Otherwise, pending logging events might be
+ lost.
+
+ <p>The <code>shutdown</code> method is careful to close nested
+ appenders before closing regular appenders. This is allows
+ configurations where a regular appender is attached to a category
+ and again to a nested appender.
+ @since 1.0
+ */
+ public
+ static
+ void shutdown() {
+ defaultHierarchy.shutdown();
+ }
+
+
+ /**
+ Log a message object with the {@link Level#WARN WARN} Level.
+
+ <p>This method first checks if this category is <code>WARN</code>
+ enabled by comparing the level of this category with {@link
+ Level#WARN WARN} Level. If the category is <code>WARN</code>
+ enabled, then it converts the message object passed as parameter
+ to a string by invoking the appropriate {@link ObjectRenderer}. It
+ proceeds to call all the registered appenders in this category and
+ also higher in the hieararchy depending on the value of the
+ additivity flag.
+
+ <p><b>WARNING</b> Note that passing a {@link Throwable} to this
+ method will print the name of the Throwable but no stack trace. To
+ print a stack trace use the {@link #warn(Object, Throwable)} form
+ instead. <p>
+
+ @param message the message object to log. */
+ public
+ void warn(Object message) {
+ if(hierarchy.enableInt > Level.WARN_INT)
+ return;
+
+ if(Level.WARN.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, Level.WARN, message, null);
+ }
+
+ /**
+ Log a message with the <code>WARN</code> level including the
+ stack trace of the {@link Throwable} <code>t</code> passed as
+ parameter.
+
+ <p>See {@link #warn(Object)} for more detailed information.
+
+ @param message the message object to log.
+ @param t the exception to log, including its stack trace. */
+ public
+ void warn(Object message, Throwable t) {
+ if(hierarchy.enableInt > Level.WARN_INT)
+ return;
+ if(Level.WARN.isGreaterOrEqual(this.getChainedLevel()))
+ forcedLog(FQCN, Level.WARN, message, t);
+ }
}
1.8 +1 -1 jakarta-log4j/src/java/org/apache/log4j/DefaultCategoryFactory.java
Index: DefaultCategoryFactory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/DefaultCategoryFactory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultCategoryFactory.java 2001/09/03 22:10:10 1.7
+++ DefaultCategoryFactory.java 2001/09/04 18:44:47 1.8
@@ -16,6 +16,6 @@
public
Logger makeNewLoggerInstance(String name) {
- return new Category(name);
+ return new Logger(name);
}
}
1.29 +6 -6 jakarta-log4j/src/java/org/apache/log4j/Hierarchy.java
Index: Hierarchy.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Hierarchy.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Hierarchy.java 2001/09/03 22:10:10 1.28
+++ Hierarchy.java 2001/09/04 18:44:47 1.29
@@ -60,7 +60,7 @@
private Vector listeners;
Hashtable ht;
- Category root;
+ Logger root;
RendererMap rendererMap;
int enableInt;
@@ -76,7 +76,7 @@
*/
public
- Hierarchy(Category root) {
+ Hierarchy(Logger root) {
ht = new Hashtable();
listeners = new Vector(1);
this.root = root;
@@ -263,24 +263,24 @@
}
public
- void fireAddAppenderEvent(Logger logger, Appender appender) {
+ void fireAddAppenderEvent(Category cat, Appender appender) {
if(listeners != null) {
int size = listeners.size();
HierarchyEventListener listener;
for(int i = 0; i < size; i++) {
listener = (HierarchyEventListener) listeners.elementAt(i);
- listener.addAppenderEvent(logger, appender);
+ listener.addAppenderEvent(cat, appender);
}
}
}
- void fireRemoveAppenderEvent(Logger logger, Appender appender) {
+ void fireRemoveAppenderEvent(Category cat, Appender appender) {
if(listeners != null) {
int size = listeners.size();
HierarchyEventListener listener;
for(int i = 0; i < size; i++) {
listener = (HierarchyEventListener) listeners.elementAt(i);
- listener.removeAppenderEvent(logger, appender);
+ listener.removeAppenderEvent(cat, appender);
}
}
}
1.2 +9 -114 jakarta-log4j/src/java/org/apache/log4j/Level.java
Index: Level.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Level.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Level.java 2001/09/02 21:48:55 1.1
+++ Level.java 2001/09/04 18:44:47 1.2
@@ -7,139 +7,33 @@
*/
// Contributors: Kitching Simon <Si...@orange.ch>
+// Nicolas Wolff
package org.apache.log4j;
/**
Defines the minimum set of priorities recognized by the system,
- that is {@link #FATAL}, {@link #ERROR}, {@link #WARN}, {@link
- #INFO} and {@link #DEBUG}.
+ that is <code>FATAL</code>, <code>ERROR</code>, <code>WARN</code>,
+ <code>INFO</code> and <code>DEBUG</code>.
<p>The <code>Level</code> class may be subclassed to define a larger
- level set.
+ priority set.
@author Ceki Gülcü
- */
-public class Level {
-
- int level;
- String levelStr;
- int syslogEquivalent;
-
- public final static int OFF_INT = Integer.MAX_VALUE;
- public final static int FATAL_INT = 50000;
- public final static int ERROR_INT = 40000;
- public final static int WARN_INT = 30000;
- public final static int INFO_INT = 20000;
- public final static int DEBUG_INT = 10000;
- public final static int ALL_INT = Integer.MIN_VALUE;
-
-
- /**
- The <code>OFF</code> is used to turn off logging.
- */
- final static public Level OFF = new Level(OFF_INT, "OFF", 0);
-
-
- /**
- The <code>FATAL</code> Level designates very severe error
- events that will presumably lead the application to abort.
- */
- final static public Level FATAL = new Level(FATAL_INT, "FATAL", 0);
-
- /**
- The <code>ERROR</code> Level designates error events that
- might still allow the application to continue running. */
- final static public Level ERROR = new Level(ERROR_INT, "ERROR", 3);
-
- /**
- The <code>WARN</code> Level designates potentially harmful situations.
- */
- final static public Level WARN = new Level(WARN_INT, "WARN", 4);
-
- /**
- The <code>INFO</code> Level designates informational messages
- that highlight the progress of the application at coarse-grained
- level. */
- final static public Level INFO = new Level(INFO_INT, "INFO", 6);
- /**
- The <code>DEBUG</code> Level designates fine-grained
- informational events that are most useful to debug an
- application. */
- final static public Level DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
-
- /**
- The <code>ALL</code> is used to turn on all logging.
- */
- final static public Level ALL = new Level(ALL_INT, "ALL", 7);
+ */
+public class Level extends Priority {
-
/**
- Instantiate a level object.
+ Instantiate a priority object.
*/
protected
Level(int level, String levelStr, int syslogEquivalent) {
- this.level = level;
- this.levelStr = levelStr;
- this.syslogEquivalent = syslogEquivalent;
- }
-
- /**
- Return the syslog equivalent of this level as an integer.
- */
- public
- final
- int getSyslogEquivalent() {
- return syslogEquivalent;
- }
-
-
- /**
- Returns the string representation of this level.
- */
- final
- public
- String toString() {
- return levelStr;
- }
-
- /**
- Returns the integer representation of this level.
- */
- public
- final
- int toInt() {
- return level;
+ super(level, levelStr, syslogEquivalent);
}
-
- /**
- Returns <code>true</code> if this level has a higher or equal
- level than the level passed as argument, <code>false</code>
- otherwise.
-
- <p>You should think twice before overriding the default
- implementation of <code>isGreaterOrEqual</code> method.
- */
- public
- boolean isGreaterOrEqual(Level r) {
- return level >= r.level;
- }
-
/**
- Return all possible priorities as an array of Level objects in
- descending order. */
- public
- static
- Level[] getAllPossiblePriorities() {
- return new Level[] {Level.FATAL, Level.ERROR, Level.WARN,
- Level.INFO, Level.DEBUG};
- }
-
-
- /**
Convert the string passed as argument to a level. If the
conversion fails, then this method returns {@link #DEBUG}.
*/
@@ -203,4 +97,5 @@
}
+
}
1.4 +2 -1038 jakarta-log4j/src/java/org/apache/log4j/Logger.java
Index: Logger.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Logger.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Logger.java 2001/09/04 14:53:12 1.3
+++ Logger.java 2001/09/04 18:44:47 1.4
@@ -5,20 +5,6 @@
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file. */
-// Contibutors: Alex Blewitt <Al...@ioshq.com>
-// Markus Oestreicher <oe...@zurich.ibm.com>
-// Frank Hoering <fh...@zurich.ibm.com>
-// Nelson Minar <ne...@media.mit.edu>
-// Jim Cakalic <ji...@na.biomerieux.com>
-// Avy Sharell <as...@club-internet.fr>
-// Ciaran Treanor <ci...@xelector.com>
-// Jeff Turner <je...@socialchange.net.au>
-// Michael Horwitz <MH...@siemens.co.za>
-// Calvin Chan <ca...@hic.gov.au>
-// Aaron Greenhouse <aa...@cs.cmu.edu>
-// Beat Meier <bm...@infovia.com.ar>
-// Colin Sampaleanu <co...@exis.com>
-
package org.apache.log4j;
import org.apache.log4j.spi.RootCategory;
@@ -52,1032 +38,10 @@
@author Ceki Gülcü
@author Anders Kristensen */
-public class Logger implements AppenderAttachable {
-
- /**
- The hierarchy where categories are attached to by default.
- */
- static
- public
- final Hierarchy defaultHierarchy = new Hierarchy(new
- RootCategory(Level.DEBUG));
-
-
- /**
- This string constant is set to <b>log4j.properties</b> the name
- of the file that will be searched by default in classpath. If the
- file can be found, then it is fed to the {@link
- PropertyConfigurator}.
-
- See also {@link #DEFAULT_CONFIGURATION_KEY} for a more general
- alternative.
-
- <p>See also the full description of <a
- href="../../../../manual.html#defaultInit">default
- intialization</a> procedure.
-
- @since 0.8.5 */
- static public final String DEFAULT_CONFIGURATION_FILE = "log4j.properties";
-
- /**
- This string constant is set to <b>log4j.configuration</b>.
-
- <p>It corresponds to name of a system property that, if set,
- specifies the name of the resource containing the properties file
- or {@link URL} with which log4j should configure itself. See
- {@link OptionConverter#selectAndConfigure} for more detailed
- information on the processing of this option.
-
- <p>Setting the <b>log4j.configuration</b> system property
- overrides the default search for the file <b>log4j.properties</b>.
-
- <p>Note that all property keys are case sensitive.
-
- <p>See also the full description of <a
- href="../../../../manual.html#defaultInit">default
- intialization</a> procedure.
-
- @since 1.0 */
- static final public String DEFAULT_CONFIGURATION_KEY="log4j.configuration";
-
- /**
- This string constant is set to <b>log4j.configuratorClass</b>.
-
- <p>It corresponds to name of a system property that, if set,
- specifies the class name to use to automatically configure
- log4j. See {@link OptionConverter#selectAndConfigure} for more
- detailed information on the processing of this option.
-
- <p>Setting the <b>log4j.configuration</b> system property
- overrides the default search for the file <b>log4j.properties</b>.
-
- <p>Note that all property keys are case sensitive.
-
- <p>See also the full description of <a
- href="../../../../manual.html#defaultInit">default
- intialization</a> procedure.
-
- @since 1.2 */
- static final public String CONFIGURATOR_CLASS_KEY="log4j.configuratorClass";
-
- /**
- Setting the system property <b>log4j.defaultInitOverride</b> to
- "true" or any other value than "false" will skip default
- configuration process.
-
- <p>The current value of the DEFAULT_INIT_OVERRIDE_KEY string
- constant is <b>log4j.defaultInitOverride</b>.
-
- <p>See also the full description of <a
- href="../../../../manual.html#defaultInit">default
- intialization</a> procedure.
-
- <p>Note that all property keys are case sensitive.
-
- @since 0.8.5 */
- public static final String DEFAULT_INIT_OVERRIDE_KEY =
- "log4j.defaultInitOverride";
-
- /** Search for the properties file log4j.properties in the CLASSPATH. */
- static {
-
- String override =OptionConverter.getSystemProperty(DEFAULT_INIT_OVERRIDE_KEY,
- null);
-
- // if there is no default init override, them get the resource
- // specified by the user or the default config file.
- if(override == null || "false".equalsIgnoreCase(override)) {
- String resource = OptionConverter.getSystemProperty(
- DEFAULT_CONFIGURATION_KEY,
- DEFAULT_CONFIGURATION_FILE);
-
- String configuratorClassName = OptionConverter.getSystemProperty(
- CONFIGURATOR_CLASS_KEY,
- null);
-
- URL url = null;
- try {
- // so, resource is not a URL:
- // attempt to get the resource from the class path
- url = new URL(resource);
- } catch (MalformedURLException ex) {
- url = Loader.getResource(resource);
- }
-
- // If we have a non-null url, then delegate the rest of the
- // configuration to the OptionConverter.selectAndConfigure
- // method.
- if(url != null) {
- LogLog.debug("Using URL ["+url+"] for automatic log4j configuration.");
- OptionConverter.selectAndConfigure(url, configuratorClassName,
- defaultHierarchy);
- } else {
- LogLog.debug("Could not find resource: ["+resource+"].");
- }
- }
- }
-
- /**
- The name of this logger.
- */
- protected String name;
-
- /**
- The assigned level of this logger. The
- <code>level</code> variable need not be assined a value in
- which case it is inherited form the hierarchy. */
- volatile protected Level level;
-
- /**
- The parent of this logger. All categories have at least one
- ancestor which is the root logger. */
- volatile protected Logger parent;
-
- /**
- The fully qualified name of the Logger class. See also the
- getFQCN method. */
- private static final String FQCN = Logger.class.getName();
-
- protected ResourceBundle resourceBundle;
-
- // Categories need to know what Hierarchy they are in
- protected Hierarchy hierarchy;
+public class Logger extends Category {
-
- AppenderAttachableImpl aai;
-
- /** Additivity is set to true by default, that is children inherit
- the appenders of their ancestors by default. If this variable is
- set to <code>false</code> then the appenders found in the
- ancestors of this logger are not used. However, the children
- of this logger will inherit its appenders, unless the children
- have their additivity flag set to <code>false</code> too. See
- the user manual for more details. */
- protected boolean additive = true;
-
- /**
- This constructor created a new <code>Logger</code> instance and
- sets its name.
-
- <p>It is intended to be used by sub-classes only. You should not
- create categories directly.
-
- @param name The name of the logger.
- */
protected
Logger(String name) {
- this.name = name;
- }
-
- /**
- Add <code>newAppender</code> to the list of appenders of this
- Logger instance.
-
- <p>If <code>newAppender</code> is already in the list of
- appenders, then it won't be added again.
- */
- synchronized
- public
- void addAppender(Appender newAppender) {
- if(aai == null) {
- aai = new AppenderAttachableImpl();
- }
- aai.addAppender(newAppender);
- hierarchy.fireAddAppenderEvent(this, newAppender);
- }
-
- /**
- If <code>assertion</code> parameter is <code>false</code>, then
- logs <code>msg</code> as an {@link #error(Object) error} statement.
-
- <p>The <code>assert</code> method has been renamed to
- <code>assertLog</code> because <code>assert</code> is a language
- reserved word in JDK 1.4.
-
- @param assertion
- @param msg The message to print if <code>assertion</code> is
- false.
-
- @since 1.2 */
- public
- void assertLog(boolean assertion, String msg) {
- if(!assertion)
- this.error(msg);
- }
-
-
- /**
- Call the appenders in the hierrachy starting at
- <code>this</code>. If no appenders could be found, emit a
- warning.
-
- <p>This method calls all the appenders inherited from the
- hierarchy circumventing any evaluation of whether to log or not
- to log the particular log request.
-
- @param LoggingEvent the event to log. */
- public
- void callAppenders(LoggingEvent event) {
- int writes = 0;
-
- for(Logger l = this; l != null; l=l.parent) {
- // Protected against simultaneous call to addAppender, removeAppender,...
- synchronized(l) {
- if(l.aai != null) {
- writes += l.aai.appendLoopOnAppenders(event);
- }
- if(!l.additive) {
- break;
- }
- }
- }
- // No appenders in hierarchy, warn user only once.
- if(!hierarchy.emittedNoAppenderWarning && writes == 0) {
- LogLog.error("No appenders could be found for logger (" +
- this.getName() + ").");
- LogLog.error("Please initialize the log4j system properly.");
- hierarchy.emittedNoAppenderWarning = true;
- }
- }
-
- /**
- Close all attached appenders implementing the AppenderAttachable
- interface.
- @since 1.0
- */
- synchronized
- void closeNestedAppenders() {
- Enumeration enum = this.getAllAppenders();
- if(enum != null) {
- while(enum.hasMoreElements()) {
- Appender a = (Appender) enum.nextElement();
- if(a instanceof AppenderAttachable) {
- a.close();
- }
- }
- }
- }
-
- /**
- Log a message object with the {@link Level#DEBUG DEBUG} level.
-
- <p>This method first checks if this logger is <code>DEBUG</code>
- enabled by comparing the level of this logger with the {@link
- Level#DEBUG DEBUG} level. If this logger is
- <code>DEBUG</code> enabled, then it converts the message object
- (passed as parameter) to a string by invoking the appropriate
- {@link ObjectRenderer}. It then proceeds to call all the
- registered appenders in this logger and also higher in the
- hierarchy depending on the value of the additivity flag.
-
- <p><b>WARNING</b> Note that passing a {@link Throwable} to this
- method will print the name of the <code>Throwable</code> but no
- stack trace. To print a stack trace use the {@link #debug(Object,
- Throwable)} form instead.
-
- @param message the message object to log. */
- public
- void debug(Object message) {
- if(hierarchy.enableInt > Level.DEBUG_INT)
- return;
- if(Level.DEBUG.isGreaterOrEqual(this.getChainedLevel())) {
- forcedLog(FQCN, Level.DEBUG, message, null);
- }
- }
-
-
- /**
- Log a message object with the <code>DEBUG</code> level including
- the stack trace of the {@link Throwable} <code>t</code> passed as
- parameter.
-
- <p>See {@link #debug(Object)} form for more detailed information.
-
- @param message the message object to log.
- @param t the exception to log, including its stack trace. */
- public
- void debug(Object message, Throwable t) {
- if(hierarchy.enableInt > Level.DEBUG_INT)
- return;
- if(Level.DEBUG.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.DEBUG, message, t);
- }
-
- //public
- //void dump() {
- // System.out.println("Logger " + name + " dump -----");
- // for(Logger c = this; c != null; c=c.parent)
- // System.out.println("("+c.name+", "+c.level+") ->");
- // System.out.println("---------------------------");
- //
- //}
-
- /**
- Log a message object with the {@link Level#ERROR ERROR} Level.
-
- <p>This method first checks if this logger is <code>ERROR</code>
- enabled by comparing the level of this logger with {@link
- Level#ERROR ERROR} Level. If this logger is
- <code>ERROR</code> enabled, then it converts the message object
- passed as parameter to a string by invoking the appropriate {@link
- ObjectRenderer}. It proceeds to call all the registered appenders
- in this logger and also higher in the hierarchy depending on
- the value of the additivity flag.
-
- <p><b>WARNING</b> Note that passing a {@link Throwable} to this
- method will print the name of the <code>Throwable</code> but no
- stack trace. To print a stack trace use the {@link #error(Object,
- Throwable)} form instead.
-
- @param message the message object to log */
- public
- void error(Object message) {
- if(hierarchy.enableInt > Level.ERROR_INT)
- return;
- if(Level.ERROR.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.ERROR, message, null);
- }
-
- /**
- Log a message object with the <code>ERROR</code> level including
- the stack trace of the {@link Throwable} <code>t</code> passed as
- parameter.
-
- <p>See {@link #error(Object)} form for more detailed information.
-
- @param message the message object to log.
- @param t the exception to log, including its stack trace. */
- public
- void error(Object message, Throwable t) {
- if(hierarchy.enableInt > Level.ERROR_INT)
- return;
- if(Level.ERROR.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.ERROR, message, t);
-
- }
-
-
- /**
- If the named logger exists (in the default hierarchy) then it
- returns a reference to the logger, otherwise it returns
- <code>null</code>.
-
- <p>Contributed by Ciaran Treanor - ciaran@xelector.com
- @version 0.8.5 */
- public
- static
- Logger exists(String name) {
- return defaultHierarchy.exists(name);
- }
-
- /**
- Log a message object with the {@link Level#FATAL FATAL} Level.
-
- <p>This method first checks if this logger is <code>FATAL</code>
- enabled by comparing the level of this logger with {@link
- Level#FATAL FATAL} Level. If the logger is <code>FATAL</code>
- enabled, then it converts the message object passed as parameter
- to a string by invoking the appropriate {@link ObjectRenderer}. It
- proceeds to call all the registered appenders in this logger and
- also higher in the hierarchy depending on the value of the
- additivity flag.
-
- <p><b>WARNING</b> Note that passing a {@link Throwable} to this
- method will print the name of the Throwable but no stack trace. To
- print a stack trace use the {@link #fatal(Object, Throwable)} form
- instead.
-
- @param message the message object to log */
- public
- void fatal(Object message) {
- if(hierarchy.enableInt > Level.FATAL_INT)
- return;
- if(Level.FATAL.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.FATAL, message, null);
- }
-
- /**
- Log a message object with the <code>FATAL</code> level including
- the stack trace of the {@link Throwable} <code>t</code> passed as
- parameter.
-
- <p>See {@link #fatal(Object)} for more detailed information.
-
- @param message the message object to log.
- @param t the exception to log, including its stack trace. */
- public
- void fatal(Object message, Throwable t) {
- if(hierarchy.enableInt > Level.FATAL_INT)
- return;
- if(Level.FATAL.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.FATAL, message, t);
- }
-
-
- /**
- This method creates a new logging event and logs the event
- without further checks. */
- protected
- void forcedLog(String fqcn, Level level, Object message, Throwable t) {
- callAppenders(new LoggingEvent(fqcn, this, level, message, t));
- }
-
-
- /**
- Get the additivity flag for this Logger instance.
- */
- public
- boolean getAdditivity() {
- return additive;
- }
-
- /**
- Get the appenders contained in this logger as an {@link
- Enumeration}. If no appenders can be found, then a {@link NullEnumeration}
- is returned.
-
- @return Enumeration An enumeration of the appenders in this logger. */
- synchronized
- public
- Enumeration getAllAppenders() {
- if(aai == null)
- return NullEnumeration.getInstance();
- else
- return aai.getAllAppenders();
- }
-
- /**
- Look for the appender named as <code>name</code>.
-
- <p>Return the appender with that name if in the list. Return
- <code>null</code> otherwise. */
- synchronized
- public
- Appender getAppender(String name) {
- if(aai == null || name == null)
- return null;
-
- return aai.getAppender(name);
- }
-
- /**
- Starting from this logger, search the logger hierarchy for a
- non-null level and return it. Otherwise, return the level of the
- root logger.
-
- <p>The Logger class is designed so that this method executes as
- quickly as possible.
- */
- public
- Level getChainedLevel() {
- for(Logger c = this; c != null; c=c.parent) {
- if(c.level != null)
- return c.level;
- }
- return null; // If reached will cause an NullPointerException.
- }
-
- /**
- Return the default Hierarchy instance.
-
- @since 1.0
- */
- public
- static
- Hierarchy getDefaultHierarchy() {
- return defaultHierarchy;
- }
-
-
- /**
- Return the the {@link Hierarchy} where this <code>Logger</code> instance is
- attached.
-
- @since 1.1 */
- public
- Hierarchy getHierarchy() {
- return hierarchy;
- }
-
-
- /**
- Retrieve a logger with named as the <code>name</code>
- parameter. If the named logger already exists, then the
- existing instance will be reutrned. Otherwise, a new instance is
- created.
-
- By default, categories do not have a set level but inherit
- it from the hierarchy. This is one of the central features of
- log4j.
-
- @param name The name of the logger to retrieve. */
- public
- static
- Logger getLogger(String name) {
- return defaultHierarchy.getLogger(name);
- }
-
- /**
- Shorthand for <code>getLogger(clazz.getName())</code>.
-
- @param clazz The name of <code>clazz</code> will be used as the
- name of the logger to retrieve. See {@link
- #getInstance(String)} for more detailed information.
- */
- public
- static
- Logger getLogger(Class clazz) {
- return getLogger(clazz.getName());
- }
-
-
- /**
- Like {@link #getInstance(String)} except that the type of logger
- instantiated depends on the type returned by the {@link
- CategoryFactory#makeNewCategoryInstance} method of the
- <code>factory</code> parameter.
-
- <p>This method is intended to be used by sub-classes.
-
- @param name The name of the category to retrieve.
-
- @param factory A {@link CategoryFactory} implementation that will
- actually create a new Instance.
-
- @since 0.8.5 */
- public
- static
- Logger getLogger(String name, LoggerFactory factory) {
- return defaultHierarchy.getLogger(name, factory);
- }
-
-
- /**
- Return the logger name. */
- public
- final
- String getName() {
- return name;
- }
-
-
- /**
- Returns the parent of this logger. Note that the parent of a
- given logger may change during the lifetime of the logger.
-
- <p>The root logger will return <code>null</code>.
-
- @since 1.2
- */
- final
- public
- Logger getParent() {
- return this.parent;
- }
-
-
- /**
- Returns the assigned {@link Level}, if any, for this Logger.
-
- @return Level - the assigned Level, can be <code>null</code>.
- */
- final
- public
- Level getLevel() {
- return this.level;
- }
-
- /**
- @deprecated Please use {@link #getLevel} instead.
- */
- final
- public
- Level getPriority() {
- return this.level;
- }
-
-
- /**
- Return the root of the default logger hierrachy.
-
- <p>The root logger is always instantiated and available. It's
- name is "root".
-
- <p>Nevertheless, calling {@link #getInstance
- Category.getInstance("root")} does not retrieve the root category
- but a category just under root named "root".
-
- */
- final
- public
- static
- Logger getRootLogger() {
- return defaultHierarchy.getRootLogger();
- }
-
- /**
- Return the <em>inherited</em> {@link ResourceBundle} for this
- logger.
-
- <p>This method walks the hierarchy to find the appropriate
- resource bundle. It will return the resource bundle attached to
- the closest ancestor of this logger, much like the way
- priorities are searched. In case there is no bundle in the
- hierarchy then <code>null</code> is returned.
-
- @since 0.9.0 */
- public
- ResourceBundle getResourceBundle() {
- for(Logger c = this; c != null; c=c.parent) {
- if(c.resourceBundle != null)
- return c.resourceBundle;
- }
- // It might be the case that there is no resource bundle
- return null;
- }
-
- /**
- Returns the string resource coresponding to <code>key</code> in
- this logger's inherited resource bundle. See also {@link
- #getResourceBundle}.
-
- <p>If the resource cannot be found, then an {@link #error error}
- message will be logged complaining about the missing resource.
- */
- protected
- String getResourceBundleString(String key) {
- ResourceBundle rb = getResourceBundle();
- // This is one of the rare cases where we can use logging in order
- // to report errors from within log4j.
- if(rb == null) {
- if(!hierarchy.emittedNoResourceBundleWarning) {
- error("No resource bundle has been set for logger "+name);
- hierarchy.emittedNoResourceBundleWarning = true;
- }
- return null;
- }
- else {
- try {
- return rb.getString(key);
- }
- catch(MissingResourceException mre) {
- error("No resource is associated with key \""+key+"\".");
- return null;
- }
- }
- }
-
- /**
- Log a message object with the {@link Level#INFO INFO} Level.
-
- <p>This method first checks if this logger is <code>INFO</code>
- enabled by comparing the level of this logger with {@link
- Level#INFO INFO} Level. If the logger is <code>INFO</code>
- enabled, then it converts the message object passed as parameter
- to a string by invoking the appropriate {@link ObjectRenderer}. It
- proceeds to call all the registered appenders in this logger and
- also higher in the hierarchy depending on the value of the
- additivity flag.
-
- <p><b>WARNING</b> Note that passing a {@link Throwable} to this
- method will print the name of the Throwable but no stack trace. To
- print a stack trace use the {@link #info(Object, Throwable)} form
- instead.
-
- @param message the message object to log */
- public
- void info(Object message) {
- if(hierarchy.enableInt > Level.INFO_INT)
- return;
- if(Level.INFO.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.INFO, message, null);
- }
-
- /**
- Log a message object with the <code>INFO</code> level including
- the stack trace of the {@link Throwable} <code>t</code> passed as
- parameter.
-
- <p>See {@link #info(Object)} for more detailed information.
-
- @param message the message object to log.
- @param t the exception to log, including its stack trace. */
- public
- void info(Object message, Throwable t) {
- if(hierarchy.enableInt > Level.INFO_INT)
- return;
- if(Level.INFO.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.INFO, message, t);
- }
-
- /**
- * Check whether this logger is enabled for the <code>DEBUG</code>
- * Level.
- *
- * <p> This function is intended to lessen the computational cost of
- * disabled log debug statements.
- *
- * <p> For some <code>cat</code> Logger object, when you write,
- * <pre>
- * cat.debug("This is entry number: " + i );
- * </pre>
- *
- * <p>You incur the cost constructing the message, concatenatiion in
- * this case, regardless of whether the message is logged or not.
- *
- * <p>If you are worried about speed, then you should write
- * <pre>
- * if(cat.isDebugEnabled()) {
- * cat.debug("This is entry number: " + i );
- * }
- * </pre>
- *
- * <p>This way you will not incur the cost of parameter
- * construction if debugging is disabled for <code>cat</code>. On
- * the other hand, if the <code>cat</code> is debug enabled, you
- * will incur the cost of evaluating whether the logger is debug
- * enabled twice. Once in <code>isDebugEnabled</code> and once in
- * the <code>debug</code>. This is an insignificant overhead
- * since evaluating a logger takes about 1%% of the time it
- * takes to actually log.
- *
- * @return boolean - <code>true</code> if this logger is debug
- * enabled, <code>false</code> otherwise.
- * */
- public
- boolean isDebugEnabled() {
- if(hierarchy.enableInt > Level.DEBUG_INT)
- return false;
- return Level.DEBUG.isGreaterOrEqual(this.getChainedLevel());
- }
-
- /**
- Check whether this logger is enabled for a given {@link
- Level} passed as parameter.
-
- See also {@link #isDebugEnabled}.
-
- @return boolean True if this logger is enabled for <code>level</code>.
- */
- public
- boolean isEnabledFor(Level level) {
- if(hierarchy.enableInt > level.level)
- return false;
- return level.isGreaterOrEqual(this.getChainedLevel());
- }
-
- /**
- Check whether this logger is enabled for the info Level.
- See also {@link #isDebugEnabled}.
-
- @return boolean - <code>true</code> if this logger is enabled
- for level info, <code>false</code> otherwise.
- */
- public
- boolean isInfoEnabled() {
- if(hierarchy.enableInt > Level.INFO_INT)
- return false;
- return Level.INFO.isGreaterOrEqual(this.getChainedLevel());
- }
-
-
- /**
- Log a localized message. The user supplied parameter
- <code>key</code> is replaced by its localized version from the
- resource bundle.
-
- @see #setResourceBundle
-
- @since 0.8.4 */
- public
- void l7dlog(Level level, String key, Throwable t) {
- if(hierarchy.enableInt > level.level) {
- return;
- }
- if(level.isGreaterOrEqual(this.getChainedLevel())) {
- String msg = getResourceBundleString(key);
- // if message corresponding to 'key' could not be found in the
- // resource bundle, then default to 'key'.
- if(msg == null) {
- msg = key;
- }
- forcedLog(FQCN, level, msg, t);
- }
- }
- /**
- Log a localized and parameterized message. First, the user
- supplied <code>key</code> is searched in the resource
- bundle. Next, the resulting pattern is formatted using
- {@link MessageFormat#format(String,Object[])} method with the user
- supplied object array <code>params</code>.
-
- @since 0.8.4
- */
- public
- void l7dlog(Level level, String key, Object[] params, Throwable t) {
- if(hierarchy.enableInt > level.level) {
- return;
- }
- if(level.isGreaterOrEqual(this.getChainedLevel())) {
- String pattern = getResourceBundleString(key);
- String msg;
- if(pattern == null)
- msg = key;
- else
- msg = java.text.MessageFormat.format(pattern, params);
- forcedLog(FQCN, level, msg, t);
- }
- }
-
- /**
- This generic form is intended to be used by wrappers.
- */
- public
- void log(Level level, Object message, Throwable t) {
- if(hierarchy.enableInt > level.level) {
- return;
- }
- if(level.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, level, message, t);
- }
-
- /**
- This generic form is intended to be used by wrappers.
- */
- public
- void log(Level level, Object message) {
- if(hierarchy.enableInt > level.level) {
- return;
- }
- if(level.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, level, message, null);
- }
-
- /**
-
- This is the most generic printing method. It is intended to be
- invoked by <b>wrapper</b> classes.
-
- @param callerFQCN The wrapper class' fully qualified class name.
- @param level The level of the logging request.
- @param message The message of the logging request.
- @param t The throwable of the logging request, may be null. */
- public
- void log(String callerFQCN, Level level, Object message, Throwable t) {
- if(hierarchy.enableInt > level.level) {
- return;
- }
- if(level.isGreaterOrEqual(this.getChainedLevel())) {
- forcedLog(callerFQCN, level, message, t);
- }
- }
-
-
- /**
- Remove all previously added appenders from this Logger
- instance.
-
- <p>This is useful when re-reading configuration information.
- */
- synchronized
- public
- void removeAllAppenders() {
- if(aai != null) {
- aai.removeAllAppenders();
- aai = null;
- }
- }
-
- /**
- Remove the appender passed as parameter form the list of appenders.
-
- @since 0.8.2
- */
- synchronized
- public
- void removeAppender(Appender appender) {
- if(appender == null || aai == null)
- return;
- aai.removeAppender(appender);
- }
-
- /**
- Remove the appender with the name passed as parameter form the
- list of appenders.
-
- @since 0.8.2 */
- synchronized
- public
- void removeAppender(String name) {
- if(name == null || aai == null) return;
- aai.removeAppender(name);
- }
-
- /**
- Set the additivity flag for this Logger instance.
- @since 0.8.1
- */
- public
- void setAdditivity(boolean additive) {
- this.additive = additive;
- }
-
- /**
- Only the Hiearchy class can set the hiearchy of a
- logger. Default package access is MANDATORY here. */
- final
- void setHierarchy(Hierarchy hierarchy) {
- this.hierarchy = hierarchy;
- }
-
- /**
- Set the level of this Logger.
-
- <p>Null values are admitted.
- */
- public
- void setLevel(Level level) {
- this.level = level;
- }
-
-
- /**
- Set the resource bundle to be used with localized logging
- methods {@link #l7dlog(Level,String,Throwable)} and {@link
- #l7dlog(Level,String,Object[],Throwable)}.
-
- @since 0.8.4
- */
- public
- void setResourceBundle(ResourceBundle bundle) {
- resourceBundle = bundle;
- }
-
- /**
- Calling this method will <em>safely</em> close and remove all
- appenders in all the categories including root contained in the
- default hierachy.
-
- <p>Some appenders such as {@link org.apache.log4j.net.SocketAppender}
- and {@link AsyncAppender} need to be closed before the
- application exists. Otherwise, pending logging events might be
- lost.
-
- <p>The <code>shutdown</code> method is careful to close nested
- appenders before closing regular appenders. This is allows
- configurations where a regular appender is attached to a logger
- and again to a nested appender.
-
- @since 1.0
- */
- public
- static
- void shutdown() {
- defaultHierarchy.shutdown();
- }
-
-
- /**
- Log a message object with the {@link Level#WARN WARN} Level.
-
- <p>This method first checks if this logger is <code>WARN</code>
- enabled by comparing the level of this logger with {@link
- Level#WARN WARN} Level. If the logger is <code>WARN</code>
- enabled, then it converts the message object passed as parameter
- to a string by invoking the appropriate {@link ObjectRenderer}. It
- proceeds to call all the registered appenders in this logger and
- also higher in the hieararchy depending on the value of the
- additivity flag.
-
- <p><b>WARNING</b> Note that passing a {@link Throwable} to this
- method will print the name of the Throwable but no stack trace. To
- print a stack trace use the {@link #warn(Object, Throwable)} form
- instead. <p>
-
- @param message the message object to log. */
- public
- void warn(Object message) {
- if(hierarchy.enableInt > Level.WARN_INT)
- return;
-
- if(Level.WARN.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.WARN, message, null);
- }
-
- /**
- Log a message with the <code>WARN</code> level including the
- stack trace of the {@link Throwable} <code>t</code> passed as
- parameter.
-
- <p>See {@link #warn(Object)} for more detailed information.
-
- @param message the message object to log.
- @param t the exception to log, including its stack trace. */
- public
- void warn(Object message, Throwable t) {
- if(hierarchy.enableInt > Level.WARN_INT)
- return;
- if(Level.WARN.isGreaterOrEqual(this.getChainedLevel()))
- forcedLog(FQCN, Level.WARN, message, t);
+ super(name);
}
}
1.14 +164 -19 jakarta-log4j/src/java/org/apache/log4j/Priority.java
Index: Priority.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Priority.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Priority.java 2001/09/04 15:23:52 1.13
+++ Priority.java 2001/09/04 18:44:47 1.14
@@ -11,29 +11,174 @@
package org.apache.log4j;
/**
- Defines the minimum set of priorities recognized by the system,
- that is {@link #FATAL}, {@link #ERROR}, {@link #WARN}, {@link
- #INFO} and {@link #DEBUG}.
-
- <p>The <code>Priority</code> class may be subclassed to define a larger
- priority set.
-
- @author Ceki Gülcü
- */
-public class Priority extends Level {
-
- final static public Priority FATAL = new Priority(FATAL_INT, "FATAL", 0);
- final static public Priority ERROR = new Priority(ERROR_INT, "ERROR", 3);
- final static public Priority WARN = new Priority(WARN_INT, "WARN", 4);
- final static public Priority INFO = new Priority(INFO_INT, "INFO", 6);
- final static public Priority DEBUG = new Priority(DEBUG_INT, "DEBUG", 7);
-
+ <font color="#AA4444">Refrain from using this class directly, use
+ the {@link Level} class instead.</font>
+
+ @author Ceki Gülcü */
+public class Priority {
+
+ int level;
+ String levelStr;
+ int syslogEquivalent;
+
+ public final static int OFF_INT = Integer.MAX_VALUE;
+ public final static int FATAL_INT = 50000;
+ public final static int ERROR_INT = 40000;
+ public final static int WARN_INT = 30000;
+ public final static int INFO_INT = 20000;
+ public final static int DEBUG_INT = 10000;
+ public final static int ALL_INT = Integer.MIN_VALUE;
+
+
+ /**
+ The <code>OFF</code> is used to turn off logging.
+ */
+ final static public Level OFF = new Level(OFF_INT, "OFF", 0);
+
+
/**
- Instantiate a level object.
+ The <code>FATAL</code> priority designates very severe error
+ events that will presumably lead the application to abort.
*/
+ final static public Level FATAL = new Level(FATAL_INT, "FATAL", 0);
+
+ /**
+ The <code>ERROR</code> priority designates error events that
+ might still allow the application to continue running. */
+ final static public Level ERROR = new Level(ERROR_INT, "ERROR", 3);
+
+ /**
+ The <code>WARN</code> priority designates potentially harmful situations.
+ */
+ final static public Level WARN = new Level(WARN_INT, "WARN", 4);
+
+ /**
+ The <code>INFO</code> priority designates informational messages
+ that highlight the progress of the application at coarse-grained
+ level. */
+ final static public Level INFO = new Level(INFO_INT, "INFO", 6);
+
+ /**
+ The <code>DEBUG</code> priority designates fine-grained
+ informational events that are most useful to debug an
+ application. */
+ final static public Level DEBUG = new Level(DEBUG_INT, "DEBUG", 7);
+
+ /**
+ The <code>ALL</code> is used to turn on all logging.
+ */
+ final static public Level ALL = new Level(ALL_INT, "ALL", 7);
+
+
+ /**
+ Instantiate a priority object.
+ */
protected
Priority(int level, String levelStr, int syslogEquivalent) {
- super(level, levelStr, syslogEquivalent);
+ this.level = level;
+ this.levelStr = levelStr;
+ this.syslogEquivalent = syslogEquivalent;
}
+
+ /**
+ Return the syslog equivalent of this priority as an integer.
+ */
+ public
+ final
+ int getSyslogEquivalent() {
+ return syslogEquivalent;
+ }
+
+
+ /**
+ Returns the string representation of this priority.
+ */
+ final
+ public
+ String toString() {
+ return levelStr;
+ }
+
+ /**
+ Returns the integer representation of this priority.
+ */
+ public
+ final
+ int toInt() {
+ return level;
+ }
+
+
+ /**
+ Returns <code>true</code> if this priority has a higher or equal
+ priority than the priority passed as argument, <code>false</code>
+ otherwise.
+
+ <p>You should think twice before overriding the default
+ implementation of <code>isGreaterOrEqual</code> method.
+
+ */
+ public
+ boolean isGreaterOrEqual(Priority r) {
+ return level >= r.level;
+ }
+
+ /**
+ Return all possible priorities as an array of Priority objects in
+ descending order. */
+ public
+ static
+ Priority[] getAllPossiblePriorities() {
+ return new Priority[] {Level.FATAL, Level.ERROR, Level.WARN,
+ Level.INFO, Level.DEBUG};
+ }
+
+
+ /**
+ Convert the string passed as argument to a priority. If the
+ conversion fails, then this method returns {@link #DEBUG}.
+
+ @deprecated Please use the {@link Level.toPLevel(String)} method instead.}
+
+
+ */
+ public
+ static
+ Level toPriority(String sArg) {
+ return Level.toPriority(sArg);
+ }
+
+ /**
+ Convert an integer passed as argument to a priority. If the
+ conversion fails, then this method returns {@link #DEBUG}.
+
+ */
+ public
+ static
+ Level toPriority(int val) {
+ return toPriority(val, Level.DEBUG);
+ }
+
+ /**
+ Convert an integer passed as argument to a priority. If the
+ conversion fails, then this method returns the specified default.
+ */
+ public
+ static
+ Level toPriority(int val, Level defaultPriority) {
+ return Level.toLevel(val, defaultPriority);
+ }
+
+ /**
+ Convert the string passed as argument to a priority. If the
+ conversion fails, then this method returns the value of
+ <code>defaultPriority</code>.
+ */
+ public
+ static
+ Level toPriority(String sArg, Level defaultPriority) {
+ return Level.toLevel(sArg, defaultPriority);
+ }
+
}
1.6 +3 -1 jakarta-log4j/src/java/org/apache/log4j/examples/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/examples/Makefile,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Makefile 2001/06/26 10:51:54 1.5
+++ Makefile 2001/09/04 18:44:47 1.6
@@ -13,7 +13,9 @@
JRMI:=NumberCruncherServer.java
-SUBDIRS :=appserver
+SUBDIRS :=
+
+#appserver
# include master-rule file
include $(DEPTH)/make/make.inc
1.15 +2 -2 jakarta-log4j/src/java/org/apache/log4j/examples/MyCategory.java
Index: MyCategory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/examples/MyCategory.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- MyCategory.java 2001/09/03 22:10:10 1.14
+++ MyCategory.java 2001/09/04 18:44:47 1.15
@@ -23,7 +23,7 @@
<p>See {@link MyCategoryTest} for a usage example.
*/
-public class MyCategory extends Category {
+public class MyCategory extends Logger {
// It's usually a good idea to add a dot suffix to the fully
// qualified class name. This makes caller localization to work
@@ -55,7 +55,7 @@
*/
public
static
- Category getInstance(String name) {
+ Logger getInstance(String name) {
return Category.getInstance(name, myFactory);
}
1.12 +2 -5 jakarta-log4j/src/java/org/apache/log4j/net/SocketNode.java
Index: SocketNode.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/SocketNode.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SocketNode.java 2001/09/02 21:40:36 1.11
+++ SocketNode.java 2001/09/04 18:44:47 1.12
@@ -16,11 +16,8 @@
import java.io.ObjectInputStream;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Hierarchy;
+import org.apache.log4j.*;
import org.apache.log4j.spi.LoggingEvent;
-import org.apache.log4j.Level;
-import org.apache.log4j.NDC;
// Contributors: Moses Hohman <mm...@rainbow.uchicago.edu>
@@ -42,7 +39,7 @@
Hierarchy hierarchy;
ObjectInputStream ois;
- static Logger logger = Logger.getLogger(SocketNode.class.getName());
+ static Logger logger = Category.getInstance(SocketNode.class);
public
SocketNode(Socket socket, Hierarchy hierarchy) {
1.4 +3 -4 jakarta-log4j/src/java/org/apache/log4j/spi/HierarchyEventListener.java
Index: HierarchyEventListener.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/HierarchyEventListener.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HierarchyEventListener.java 2001/09/02 21:40:36 1.3
+++ HierarchyEventListener.java 2001/09/04 18:44:47 1.4
@@ -7,8 +7,7 @@
package org.apache.log4j.spi;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Appender;
+import org.apache.log4j.*;
/**
Listen to events occuring within a {@link
@@ -26,10 +25,10 @@
public
- void addAppenderEvent(Logger logger, Appender appender);
+ void addAppenderEvent(Category cat, Appender appender);
public
- void removeAppenderEvent(Logger logger, Appender appender);
+ void removeAppenderEvent(Category cat, Appender appender);
}
1.2 +2 -4 jakarta-log4j/src/java/org/apache/log4j/spi/LoggerRepository.java
Index: LoggerRepository.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/LoggerRepository.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LoggerRepository.java 2001/09/03 22:33:21 1.1
+++ LoggerRepository.java 2001/09/04 18:44:47 1.2
@@ -1,9 +1,7 @@
package org.apache.log4j.spi;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Appender;
-
+import org.apache.log4j.*;
import java.util.Enumeration;
public interface LoggerRepository {
@@ -28,7 +26,7 @@
Enumeration getCurrentLoggers();
public
- void fireAddAppenderEvent(Logger logger, Appender appender);
+ void fireAddAppenderEvent(Category cat, Appender appender);
public
void resetConfiguration();
1.21 +10 -13 jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
Index: LoggingEvent.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- LoggingEvent.java 2001/09/02 21:40:36 1.20
+++ LoggingEvent.java 2001/09/04 18:44:47 1.21
@@ -7,10 +7,7 @@
package org.apache.log4j.spi;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Level;
-import org.apache.log4j.NDC;
-import org.apache.log4j.MDC;
+import org.apache.log4j.*;
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.helpers.Loader;
@@ -42,17 +39,17 @@
private static long startTime = System.currentTimeMillis();
- /** Fully qualified name of the calling logger class. */
- transient public final String fqnOfLoggerClass;
+ /** Fully qualified name of the calling category class. */
+ transient public final String fqnOfCategoryClass;
- /** The logger of the logging event. The logger field is not
+ /** The category of the logging event. The category field is not
serialized for performance reasons.
<p>It is set by the LoggingEvent constructor or set by a remote
entity after deserialization. */
- transient public Logger logger;
+ transient public Category logger;
- /** The logger name. */
+ /** The level name. */
public final String loggerName;
/** Level of logging event. Level cannot be serializable
@@ -117,13 +114,13 @@
<p>Except {@link #timeStamp} all the other fields of
<code>LoggingEvent</code> are filled when actually needed.
<p>
- @param logger The logger of this event.
+ @param category The category of this event.
@param level The level of this event.
@param message The message of this event.
@param throwable The throwable of this event. */
- public LoggingEvent(String fqnOfLoggerClass, Logger logger,
+ public LoggingEvent(String fqnOfCategoryClass, Category logger,
Level level, Object message, Throwable throwable) {
- this.fqnOfLoggerClass = fqnOfLoggerClass;
+ this.fqnOfCategoryClass = fqnOfCategoryClass;
this.logger = logger;
this.loggerName = logger.getName();
this.level = level;
@@ -143,7 +140,7 @@
public
LocationInfo getLocationInformation() {
if(locationInfo == null) {
- locationInfo = new LocationInfo(new Throwable(), fqnOfLoggerClass);
+ locationInfo = new LocationInfo(new Throwable(), fqnOfCategoryClass);
}
return locationInfo;
}
1.8 +10 -3 jakarta-log4j/src/java/org/apache/log4j/spi/RootCategory.java
Index: RootCategory.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/RootCategory.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- RootCategory.java 2001/09/02 20:05:40 1.7
+++ RootCategory.java 2001/09/04 18:44:47 1.8
@@ -7,8 +7,7 @@
package org.apache.log4j.spi;
-import org.apache.log4j.Category;
-import org.apache.log4j.Level;
+import org.apache.log4j.*;
import org.apache.log4j.helpers.LogLog;
// Contibutors: Mathias Bogaert
@@ -25,7 +24,7 @@
@author Ceki Gülcü
*/
-final public class RootCategory extends Category {
+final public class RootCategory extends Logger {
/**
The root category names itself as "root". However, the root
@@ -64,4 +63,12 @@
this.level = level;
}
}
+
+ final
+ public
+ void setPriority(Level level) {
+ setLevel(level);
+ }
+
+
}
1.3 +3 -3 jakarta-log4j/src/java/org/apache/log4j/test/CustomCategoryTest.java
Index: CustomCategoryTest.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/CustomCategoryTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CustomCategoryTest.java 2001/09/02 20:05:40 1.2
+++ CustomCategoryTest.java 2001/09/04 18:44:48 1.3
@@ -12,7 +12,7 @@
import org.apache.log4j.NDC;
import org.apache.log4j.Level;
import org.apache.log4j.xml.examples.XLevel;
-import org.apache.log4j.xml.examples.XCategory;
+import org.apache.log4j.xml.examples.XLogger;
import java.io.IOException;
import java.util.Enumeration;
@@ -24,8 +24,8 @@
public class CustomCategoryTest {
- static XCategory cat = (XCategory)
- XCategory.getInstance(CustomCategoryTest.class);
+ static XLogger cat = (XLogger)
+ XLogger.getInstance(CustomCategoryTest.class);
public
static
1.5 +1 -1 jakarta-log4j/src/java/org/apache/log4j/test/FQCNTest.java
Index: FQCNTest.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/FQCNTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FQCNTest.java 2001/09/03 22:10:10 1.4
+++ FQCNTest.java 2001/09/04 18:44:48 1.5
@@ -88,7 +88,7 @@
public
static
X1Logger getX1Logger(String name) {
- return ((X1Logger) Logger.getLogger(name, factory));
+ return ((X1Logger) Category.getInstance(name, factory));
}
}
1.19 +2 -1 jakarta-log4j/src/java/org/apache/log4j/test/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/Makefile,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Makefile 2001/09/04 14:53:13 1.18
+++ Makefile 2001/09/04 18:44:48 1.19
@@ -30,7 +30,8 @@
FQCNTest.java\
DRFATest.java\
MDCStress.java\
- HeavyLoad.java\
+
+# HeavyLoad.java\
ifdef $(ISJDK1)
JSOURCES:=$(JSOURCES) UnitTestOR.java
1.2 +2 -2 jakarta-log4j/src/java/org/apache/log4j/test/SocketAppenderTest.java
Index: SocketAppenderTest.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/SocketAppenderTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SocketAppenderTest.java 2001/03/21 20:52:14 1.1
+++ SocketAppenderTest.java 2001/09/04 18:44:48 1.2
@@ -10,7 +10,7 @@
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.Category;
import org.apache.log4j.NDC;
-import org.apache.log4j.xml.examples.XCategory;
+import org.apache.log4j.xml.examples.XLogger;
import org.apache.log4j.Priority;
import java.io.IOException;
import java.util.Enumeration;
@@ -20,7 +20,7 @@
*/
public class SocketAppenderTest {
- static XCategory cat = (XCategory) XCategory.getInstance(SocketAppenderTest.class);
+ static XLogger cat = (XLogger) XLogger.getInstance(SocketAppenderTest.class);
public
static
1.2 +31 -38 jakarta-log4j/src/java/org/apache/log4j/test/UnitTestLogger.java
Index: UnitTestLogger.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/UnitTestLogger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnitTestLogger.java 2001/09/02 21:40:36 1.1
+++ UnitTestLogger.java 2001/09/04 18:44:48 1.2
@@ -7,15 +7,8 @@
package org.apache.log4j.test;
-import org.apache.log4j.spi.LoggingEvent;
-import org.apache.log4j.Logger;
-import org.apache.log4j.FileAppender;
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Appender;
-import org.apache.log4j.AppenderSkeleton;
-import org.apache.log4j.Level;
-import org.apache.log4j.Hierarchy;
-import org.apache.log4j.spi.RootCategory;
+import org.apache.log4j.*;
+import org.apache.log4j.spi.*;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -75,7 +68,7 @@
*/
public
void testAppender1() {
- cat = Logger.getLogger("test");
+ cat = Category.getInstance("test");
a1 = new FileAppender();
a1.setName("testAppender1");
cat.addAppender(a1);
@@ -96,7 +89,7 @@
a2 = new FileAppender();
a2.setName("testAppender2.2");
- cat = Logger.getLogger("test");
+ cat = Category.getInstance("test");
cat.addAppender(a1);
cat.addAppender(a2);
cat.removeAppender("testAppender2.1");
@@ -111,8 +104,8 @@
*/
public
void testAdditivity1() {
- Logger a = Logger.getLogger("a");
- Logger ab = Logger.getLogger("a.b");
+ Logger a = Category.getInstance("a");
+ Logger ab = Category.getInstance("a.b");
CountingAppender ca = new CountingAppender();
a.addAppender(ca);
@@ -132,10 +125,10 @@
public
void testAdditivity2() {
- Logger a = Logger.getLogger("a");
- Logger ab = Logger.getLogger("a.b");
- Logger abc = Logger.getLogger("a.b.c");
- Logger x = Logger.getLogger("x");
+ Logger a = Category.getInstance("a");
+ Logger ab = Category.getInstance("a.b");
+ Logger abc = Category.getInstance("a.b.c");
+ Logger x = Category.getInstance("x");
CountingAppender ca1 = new CountingAppender();
CountingAppender ca2 = new CountingAppender();
@@ -166,11 +159,11 @@
public
void testAdditivity3() {
- Logger root = Logger.getRootLogger();
- Logger a = Logger.getLogger("a");
- Logger ab = Logger.getLogger("a.b");
- Logger abc = Logger.getLogger("a.b.c");
- Logger x = Logger.getLogger("x");
+ Logger root = Category.getRoot();
+ Logger a = Category.getInstance("a");
+ Logger ab = Category.getInstance("a.b");
+ Logger abc = Category.getInstance("a.b.c");
+ Logger x = Category.getInstance("x");
CountingAppender caRoot = new CountingAppender();
CountingAppender caA = new CountingAppender();
@@ -208,7 +201,7 @@
public
void testDisable1() {
CountingAppender caRoot = new CountingAppender();
- Logger root = Logger.getRootLogger();
+ Logger root = Category.getRoot();
root.addAppender(caRoot);
Hierarchy h = Logger.getDefaultHierarchy();
@@ -247,14 +240,14 @@
public
void testRB1() {
- Logger root = Logger.getRootLogger();
+ Logger root = Category.getRoot();
root.setResourceBundle(rbUS);
ResourceBundle t = root.getResourceBundle();
assertSame(t, rbUS);
- Logger x = Logger.getLogger("x");
- Logger x_y = Logger.getLogger("x.y");
- Logger x_y_z = Logger.getLogger("x.y.z");
+ Logger x = Category.getInstance("x");
+ Logger x_y = Category.getInstance("x.y");
+ Logger x_y_z = Category.getInstance("x.y.z");
t = x.getResourceBundle(); assertSame(t, rbUS);
t = x_y.getResourceBundle(); assertSame(t, rbUS);
@@ -263,14 +256,14 @@
public
void testRB2() {
- Logger root = Logger.getRootLogger();
+ Logger root = Category.getRoot();
root.setResourceBundle(rbUS);
ResourceBundle t = root.getResourceBundle();
assertSame(t, rbUS);
- Logger x = Logger.getLogger("x");
- Logger x_y = Logger.getLogger("x.y");
- Logger x_y_z = Logger.getLogger("x.y.z");
+ Logger x = Category.getInstance("x");
+ Logger x_y = Category.getInstance("x.y");
+ Logger x_y_z = Category.getInstance("x.y.z");
x_y.setResourceBundle(rbFR);
t = x.getResourceBundle(); assertSame(t, rbUS);
@@ -281,14 +274,14 @@
public
void testRB3() {
- Logger root = Logger.getRootLogger();
+ Logger root = Category.getRoot();
root.setResourceBundle(rbUS);
ResourceBundle t = root.getResourceBundle();
assertSame(t, rbUS);
- Logger x = Logger.getLogger("x");
- Logger x_y = Logger.getLogger("x.y");
- Logger x_y_z = Logger.getLogger("x.y.z");
+ Logger x = Category.getInstance("x");
+ Logger x_y = Category.getInstance("x.y");
+ Logger x_y_z = Category.getInstance("x.y.z");
x_y.setResourceBundle(rbFR);
x_y_z.setResourceBundle(rbCH);
@@ -299,9 +292,9 @@
public
void testExists() {
- Logger a = Logger.getLogger("a");
- Logger a_b = Logger.getLogger("a.b");
- Logger a_b_c = Logger.getLogger("a.b.c");
+ Logger a = Category.getInstance("a");
+ Logger a_b = Category.getInstance("a.b");
+ Logger a_b_c = Category.getInstance("a.b.c");
Logger t;
t = Logger.exists("xx"); assertNull(t);
1.32 +2 -2 jakarta-log4j/src/java/org/apache/log4j/xml/DOMConfigurator.java
Index: DOMConfigurator.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/DOMConfigurator.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- DOMConfigurator.java 2001/09/03 22:10:10 1.31
+++ DOMConfigurator.java 2001/09/04 18:44:48 1.32
@@ -301,9 +301,9 @@
LogLog.debug("Desired category sub-class: ["+className+']');
try {
Class clazz = Loader.loadClass(className);
- Method getInstanceMethod = clazz.getMethod("getInstance",
+ Method getInstanceMethod = clazz.getMethod("getLogger",
ONE_STRING_PARAM);
- cat = (Category) getInstanceMethod.invoke(null, new Object[] {catName});
+ cat = (Logger) getInstanceMethod.invoke(null, new Object[] {catName});
} catch (Exception oops) {
LogLog.error("Could not retrieve category ["+catName+
"]. Reported error follows.", oops);
1.4 +1 -1 jakarta-log4j/src/java/org/apache/log4j/xml/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile 2001/03/21 21:34:28 1.3
+++ Makefile 2001/09/04 18:44:48 1.4
@@ -5,7 +5,7 @@
XMLLayout.java\
-SUBDIRS :=test examples
+SUBDIRS := examples test
# include master-rule file
include $(DEPTH)/make/make.inc
1.5 +1 -1 jakarta-log4j/src/java/org/apache/log4j/xml/examples/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/examples/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Makefile 2001/09/02 20:05:40 1.4
+++ Makefile 2001/09/04 18:44:48 1.5
@@ -2,7 +2,7 @@
PKG_DIR :=org/apache/log4j/xml/examples
DEPTH :=../../../../../../..
JSOURCES:=ReportParserError.java XMLSample.java XLevel.java\
- XCategory.java XTest.java
+ XLogger.java XTest.java
1.5 +1 -1 jakarta-log4j/src/java/org/apache/log4j/xml/examples/XTest.java
Index: XTest.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/examples/XTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XTest.java 2001/09/02 20:05:40 1.4
+++ XTest.java 2001/09/04 18:44:48 1.5
@@ -54,7 +54,7 @@
static
void sample() {
int i = -1;
- XCategory cat = (XCategory) XCategory.getInstance("some.cat");
+ XLogger cat = (XLogger) XLogger.getInstance("some.cat");
Category root = Category.getRoot();
cat.trace("Message " + ++i);
1.5 +2 -3 jakarta-log4j/src/java/org/apache/log4j/xml/test/SubClassTest.java
Index: SubClassTest.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/test/SubClassTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SubClassTest.java 2001/01/19 16:45:42 1.4
+++ SubClassTest.java 2001/09/04 18:44:48 1.5
@@ -5,7 +5,7 @@
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
import org.apache.log4j.xml.examples.ReportParserError;
-import org.apache.log4j.xml.examples.XCategory;
+import org.apache.log4j.xml.examples.XLogger;
//import org.apache.xerces.parsers.DOMParser;
//import java.io.FileInputStream;
//import org.xml.sax.InputSource;
@@ -15,8 +15,7 @@
*/
public class SubClassTest {
- static XCategory cat = (XCategory)
- XCategory.getInstance(SubClassTest.class.getName());
+ static XLogger cat = (XLogger) XLogger.getInstance(SubClassTest.class);
public
1.3 +4 -3 jakarta-log4j/src/java/org/apache/log4j/xml/test/XTest.java
Index: XTest.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/test/XTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XTest.java 2001/09/02 20:05:40 1.2
+++ XTest.java 2001/09/04 18:44:48 1.3
@@ -11,17 +11,18 @@
import org.apache.log4j.Category;
import org.apache.log4j.Level;
-import org.apache.log4j.xml.examples.XLevel;
-import org.apache.log4j.xml.examples.XCategory;
+import org.apache.log4j.xml.examples.*;
+
/**
@author Ceki Gülcü
*/
public class XTest {
- static XCategory cat = (XCategory) XCategory.getInstance(XTest.class);
+
+ static XLogger cat = (XLogger) XLogger.getInstance(XTest.class.getName());
public
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-cvs-help@jakarta.apache.org