User: starksm
Date: 01/06/19 21:02:39
Added: src/main/org/jboss/logging/log4j JBossCategory.java
TracePriority.java
Log:
Add custom log4j category that support trace level msgs
Revision Changes Path
1.1 jboss/src/main/org/jboss/logging/log4j/JBossCategory.java
Index: JBossCategory.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.logging.log4j;
import org.apache.log4j.Category;
import org.apache.log4j.spi.CategoryFactory;
/** A custom log4j category that adds support for trace() level logging.
@see #trace(String)
@see #trace(String, Throwable)
@see TracePriority
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class JBossCategory extends Category
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
private static CategoryFactory factory = new JBossCategoryFactory();
// Static --------------------------------------------------------
/** This method overrides {@link Category#getInstance} by supplying
its own factory type as a parameter.
*/
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.
*/
public static Category getInstance(Class clazz)
{
return Category.getInstance(clazz.getName(), factory);
}
// Constructors --------------------------------------------------
/** Creates new JBossCategory with the given category name.
@param name, the category name.
*/
public JBossCategory(String name)
{
super(name);
}
/** 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 isTraceEnabled()
{
if( hierarchy.isDisabled(TracePriority.TRACE_INT) )
return false;
return TracePriority.TRACE.isGreaterOrEqual(this.getChainedPriority());
}
/** Issue a log msg with a priority of TRACE.
Invokes super.log(TracePriority.TRACE, message);
*/
public void trace(String message)
{
super.log(TracePriority.TRACE, message);
}
/** Issue a log msg and throwable with a priority of TRACE.
Invokes super.log(TracePriority.TRACE, message, t);
*/
public void trace(String message, Throwable t)
{
super.log(TracePriority.TRACE, message, t);
}
// Inner classes -------------------------------------------------
/** The CategoryFactory implementation for the custom JBossCategory.
*/
public static class JBossCategoryFactory implements CategoryFactory
{
public Category makeNewCategoryInstance(String name)
{
return new JBossCategory(name);
}
}
}
1.1 jboss/src/main/org/jboss/logging/log4j/TracePriority.java
Index: TracePriority.java
===================================================================
/*
* JBoss, the OpenSource EJB server
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.logging.log4j;
import org.apache.log4j.Priority;
/** Adds a trace priority that is below the standard log4j DEBUG priority.
This is a custom priority that is 100 below the Priority.DEBUG_INT and
represents a lower priority useful for logging events that should only
be displayed when deep debugging is required.
@see org.apache.log4j.Category
@see org.apache.log4j.Priority
@author [EMAIL PROTECTED]
@version $Revision: 1.1 $
*/
public class TracePriority extends Priority
{
// Constants -----------------------------------------------------
/** The integer representation of the priority, (Priority.DEBUG_INT - 100) */
public static final int TRACE_INT = Priority.DEBUG_INT - 100;
/** The TRACE priority object singleton */
public static final TracePriority TRACE = new TracePriority(TRACE_INT, "TRACE");
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
/** Convert an integer passed as argument to a priority. If the conversion
fails, then this method returns the specified default.
@return the Priority object for name if one exists, defaultPriority otherwize.
*/
public static Priority toPriority(String name, Priority defaultPriority)
{
if( name == null )
return TRACE;
Priority p = TRACE;
if( name.charAt(0) != 'T' )
p = Priority.toPriority(name, defaultPriority);
return p;
}
/** Convert an integer passed as argument to a priority. If the conversion
fails, then this method returns the specified default.
@return the Priority object for i if one exists, defaultPriority otherwize.
*/
public static Priority toPriority(int i, Priority defaultPriority)
{
Priority p;
if( i == TRACE_INT )
p = TRACE;
else
p = Priority.toPriority(i);
return p;
}
// Constructors --------------------------------------------------
protected TracePriority(int level, String strLevel)
{
super(level, strLevel, 7);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development