User: starksm
Date: 01/11/25 19:16:10
Modified: src/main/org/jboss/logging Logger.java
Removed: src/main/org/jboss/logging LoggerFactory.java
Log:
Clean up the Logger class to not be a subclass of org.apache.log4j.Category
and support only a single factory method called getLogger to be consistent
with the 1.2 logj api and the java.util.logging api.
Drop the custom category factory as it is no longer used
Revision Changes Path
1.15 +136 -49 jboss/src/main/org/jboss/logging/Logger.java
Index: Logger.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/Logger.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Logger.java 2001/11/15 23:42:22 1.14
+++ Logger.java 2001/11/26 03:16:09 1.15
@@ -7,65 +7,33 @@
package org.jboss.logging;
import org.apache.log4j.Category;
-import org.apache.log4j.spi.CategoryFactory;
+import org.apache.log4j.Priority;
-/** A custom log4j Category subclass that add a trace level priority.
+/** A custom log4j Category wrapper that adds a trace level priority and only
+ exposes the relevent factory and logging methods.
+
* @see #isTraceEnabled
* @see #trace(Object message)
* @see #trace(Object, Throwable)
* @author [EMAIL PROTECTED]
- * @version $Revision: 1.14 $
+ * @version $Revision: 1.15 $
*/
-public class Logger extends Category
+public class Logger
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- private static CategoryFactory factory = new LoggerFactory();
+ private Category log;
// Static --------------------------------------------------------
- /** This method overrides {@link Category#getInstance} by supplying
- its own factory type as a parameter.
- @param name, the category name
- */
- public static Category getInstance(String name)
- {
- return Category.getInstance(name, factory);
- }
- /** This method overrides {@link Category#getInstance} by supplying
- its own factory type as a parameter.
- @param clazz, the Class whose name will be used as the category name
- */
- public static Category getInstance(Class clazz)
- {
- return Category.getInstance(clazz.getName(), factory);
- }
/** Create a Logger instance given the category name.
@param name, the category name
*/
- public static Logger create(String name)
- {
- Logger logger = (Logger) Category.getInstance(name, factory);
- return logger;
- }
- /** Create a Logger instance given the category class. This simply
- calls create(clazz.getName()).
- @param clazz, the Class whose name will be used as the category name
- */
- public static Logger create(Class clazz)
- {
- Logger logger = (Logger) Category.getInstance(clazz.getName(), factory);
- return logger;
- }
-
- /** Create a Logger instance given the category name.
- @param name, the category name
- */
public static Logger getLogger(String name)
{
- Logger logger = (Logger) Category.getInstance(name, factory);
+ Logger logger = new Logger(name);
return logger;
}
/** Create a Logger instance given the category class. This simply
@@ -74,7 +42,7 @@
*/
public static Logger getLogger(Class clazz)
{
- Logger logger = (Logger) Category.getInstance(clazz.getName(), factory);
+ Logger logger = new Logger(clazz.getName());
return logger;
}
@@ -82,9 +50,14 @@
/** Creates new JBossCategory with the given category name.
@param name, the category name.
*/
- public Logger(String name)
+ protected Logger(String name)
+ {
+ log = Category.getInstance(name);
+ }
+
+ public Category getCategory()
{
- super(name);
+ return log;
}
/** Check to see if the TRACE priority is enabled for this category.
@@ -93,23 +66,137 @@
*/
public boolean isTraceEnabled()
{
- if( hierarchy.isDisabled(TracePriority.TRACE_INT) )
+ if( log.isEnabledFor(TracePriority.TRACE) == false )
return false;
- return TracePriority.TRACE.isGreaterOrEqual(this.getChainedPriority());
+ return TracePriority.TRACE.isGreaterOrEqual(log.getChainedPriority());
}
/** Issue a log msg with a priority of TRACE.
- Invokes super.log(TracePriority.TRACE, message);
+ Invokes log.log(TracePriority.TRACE, message);
*/
public void trace(Object message)
{
- super.log(TracePriority.TRACE, message);
+ log.log(TracePriority.TRACE, message);
}
/** Issue a log msg and throwable with a priority of TRACE.
- Invokes super.log(TracePriority.TRACE, message, t);
+ Invokes log.log(TracePriority.TRACE, message, t);
*/
public void trace(Object message, Throwable t)
+ {
+ log.log(TracePriority.TRACE, message, t);
+ }
+
+ /** Check to see if the TRACE priority is enabled for this category.
+ @return true if a {@link #trace(String)} method invocation would pass
+ the msg to the configured appenders, false otherwise.
+ */
+ public boolean isDebugEnabled()
+ {
+ Priority p = Priority.DEBUG;
+ if( log.isEnabledFor(p) == false )
+ return false;
+ return p.isGreaterOrEqual(log.getChainedPriority());
+ }
+
+ /** Issue a log msg with a priority of DEBUG.
+ Invokes log.log(Priority.DEBUG, message);
+ */
+ public void debug(Object message)
+ {
+ log.log(Priority.DEBUG, message);
+ }
+ /** Issue a log msg and throwable with a priority of DEBUG.
+ Invokes log.log(Priority.DEBUG, message, t);
+ */
+ public void debug(Object message, Throwable t)
+ {
+ log.log(Priority.DEBUG, message, t);
+ }
+
+ /** Check to see if the INFO priority is enabled for this category.
+ @return true if a {@link #info(String)} method invocation would pass
+ the msg to the configured appenders, false otherwise.
+ */
+ public boolean isInfoEnabled()
+ {
+ Priority p = Priority.INFO;
+ if( log.isEnabledFor(p) == false )
+ return false;
+ return p.isGreaterOrEqual(log.getChainedPriority());
+ }
+
+ /** Issue a log msg with a priority of INFO.
+ Invokes log.log(Priority.INFO, message);
+ */
+ public void info(Object message)
+ {
+ log.log(Priority.INFO, message);
+ }
+ /** Issue a log msg and throwable with a priority of INFO.
+ Invokes log.log(Priority.INFO, message, t);
+ */
+ public void info(Object message, Throwable t)
+ {
+ log.log(Priority.INFO, message, t);
+ }
+
+ /** Issue a log msg with a priority of WARN.
+ Invokes log.log(Priority.WARN, message);
+ */
+ public void warn(Object message)
+ {
+ log.log(Priority.WARN, message);
+ }
+ /** Issue a log msg and throwable with a priority of WARN.
+ Invokes log.log(Priority.WARN, message, t);
+ */
+ public void warn(Object message, Throwable t)
+ {
+ log.log(Priority.WARN, message, t);
+ }
+
+ /** Issue a log msg with a priority of ERROR.
+ Invokes log.log(Priority.ERROR, message);
+ */
+ public void error(Object message)
+ {
+ log.log(Priority.ERROR, message);
+ }
+ /** Issue a log msg and throwable with a priority of ERROR.
+ Invokes log.log(Priority.ERROR, message, t);
+ */
+ public void error(Object message, Throwable t)
+ {
+ log.log(Priority.ERROR, message, t);
+ }
+
+ /** Issue a log msg with a priority of FATAL.
+ Invokes log.log(Priority.FATAL, message);
+ */
+ public void fatal(Object message)
+ {
+ log.log(Priority.FATAL, message);
+ }
+ /** Issue a log msg and throwable with a priority of FATAL.
+ Invokes log.log(Priority.FATAL, message, t);
+ */
+ public void fatal(Object message, Throwable t)
+ {
+ log.log(Priority.FATAL, message, t);
+ }
+
+ /** Issue a log msg with the given priority.
+ Invokes log.log(p, message);
+ */
+ public void log(Priority p, Object message)
+ {
+ log.log(p, message);
+ }
+ /** Issue a log msg with the given priority.
+ Invokes log.log(p, message, t);
+ */
+ public void log(Priority p, Object message, Throwable t)
{
- super.log(TracePriority.TRACE, message, t);
+ log.log(p, message, t);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development