User: ejort
Date: 02/02/08 13:35:39
Added: src/main/org/jboss/mx/logging/log4j Log4jAdapter.java
Log4jAdapterFactory.java TracePriority.java
package.html
Log:
Initial version of logging - might be over-engineered?
Revision Changes Path
1.1 jmx/src/main/org/jboss/mx/logging/log4j/Log4jAdapter.java
Index: Log4jAdapter.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.logging.log4j;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
import org.jboss.mx.logging.LoggerAdapter;
/**
* An adapter for the log4j Category.<p>
*
* Note: the level is interpreted as a log4j priority.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public final class Log4jAdapter
implements LoggerAdapter
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
/**
* The log4j category.
*/
Category category;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
/**
* Construct a new log4j adapter, the name is used to contruct the category.
*
* @param name the log4j category name
*/
public Log4jAdapter(String name)
{
category = Category.getInstance(name);
}
// LoggerAdapter Implementation ----------------------------------
public final String getName()
{
return category.getName();
}
public final int getLevel()
{
return category.getPriority().toInt();
}
public final void setLevel(int level)
throws SecurityException
{
category.setPriority(Priority.toPriority(level));
}
public final void log(int level, String message)
{
category.log(Priority.toPriority(level), message);
}
public final void log(int level, String message, Throwable throwable)
{
category.log(Priority.toPriority(level), message);
}
public final boolean isEnabled(int level)
{
Priority p = Priority.toPriority(level);
if (category.isEnabledFor(p) == false)
return false;
return p.isGreaterOrEqual(category.getChainedPriority());
}
public final void fatal(String message)
{
category.fatal(message);
}
public final void fatal(String message, Throwable throwable)
{
category.fatal(message, throwable);
}
public final boolean isFatalEnabled()
{
Priority p = Priority.FATAL;
if (category.isEnabledFor(p) == false)
return false;
return p.isGreaterOrEqual(category.getChainedPriority());
}
public final void error(String message)
{
category.error(message);
}
public final void error(String message, Throwable throwable)
{
category.error(message, throwable);
}
public final boolean isErrorEnabled()
{
Priority p = Priority.ERROR;
if (category.isEnabledFor(p) == false)
return false;
return p.isGreaterOrEqual(category.getChainedPriority());
}
public final void warn(String message)
{
category.warn(message);
}
public final void warn(String message, Throwable throwable)
{
category.warn(message, throwable);
}
public final boolean isWarnEnabled()
{
Priority p = Priority.WARN;
if (category.isEnabledFor(p) == false)
return false;
return p.isGreaterOrEqual(category.getChainedPriority());
}
public final void info(String message)
{
category.info(message);
}
public final void info(String message, Throwable throwable)
{
category.info(message, throwable);
}
public final boolean isInfoEnabled()
{
Priority p = Priority.INFO;
if (category.isEnabledFor(p) == false)
return false;
return p.isGreaterOrEqual(category.getChainedPriority());
}
public final void debug(String message)
{
category.debug(message);
}
public final void debug(String message, Throwable throwable)
{
category.debug(message, throwable);
}
public final boolean isDebugEnabled()
{
Priority p = Priority.DEBUG;
if (category.isEnabledFor(p) == false)
return false;
return p.isGreaterOrEqual(category.getChainedPriority());
}
public final void trace(String message)
{
category.log(TracePriority.TRACE, message);
}
public final void trace(String message, Throwable throwable)
{
category.log(TracePriority.TRACE, message, throwable);
}
public final boolean isTraceEnabled()
{
Priority p = TracePriority.TRACE;
if (category.isEnabledFor(p) == false)
return false;
return p.isGreaterOrEqual(category.getChainedPriority());
}
/**
* Retrieve the log4j category
*
* @return the category.
*/
public Object getUnderlyingLogger()
{
return category;
}
// Y Overrides ---------------------------------------------------
// Protected -----------------------------------------------------
// Package Private -----------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
1.1 jmx/src/main/org/jboss/mx/logging/log4j/Log4jAdapterFactory.java
Index: Log4jAdapterFactory.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.logging.log4j;
import org.jboss.mx.logging.LoggerAdapter;
import org.jboss.mx.logging.LoggerAdapterFactorySupport;
/**
* Creates adapters for log4j categories.
*
* @see Log4jAdapter
*
* @author <a href="mailto:[EMAIL PROTECTED]">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public final class Log4jAdapterFactory
extends LoggerAdapterFactorySupport
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// LoggerAdapterFactory Implementation --------------------------
public final LoggerAdapter getLoggerAdapter(String name)
{
return new Log4jAdapter(name);
}
public final Class getLoggerAdapterClass()
{
return Log4jAdapter.class;
}
public final void setConfiguration(Object configurator)
throws SecurityException
{
//TODO
}
public final void resetConfiguration()
throws SecurityException
{
//TODO
}
// Y Overrides ---------------------------------------------------
// Protected -----------------------------------------------------
// Package Private -----------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
1.1 jmx/src/main/org/jboss/mx/logging/log4j/TracePriority.java
Index: TracePriority.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mx.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 <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
* @version $Revision: 1.1 $
*/
public class TracePriority
extends Priority
{
/** 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");
/**
* 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;
}
protected TracePriority(int level, String strLevel)
{
super(level, strLevel, 7);
}
}
1.1 jmx/src/main/org/jboss/mx/logging/log4j/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!--
JBoss, the OpenSource J2EE webOS
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
-->
<!-- $Id: package.html,v 1.1 2002/02/08 21:35:39 ejort Exp $ -->
</head>
<body bgcolor="white">
<p><em>The JBossMX log4j adapter</em>.
<h2>Package Specification</h2>
<ul>
<li> An adapter to the log4j logging implementation
</ul>
<h2>Related Documentation</h2>
<ul>
<li> TODO link to log4j
</ul>
<h2>Package Status</h2>
<ul>
<li><font color="red"><b>ALPHA</b></font>
</ul>
<!-- Put @see and @since tags down here. -->
</body>
</html>
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development