User: user57
Date: 02/02/24 02:16:53
Added: src/main/org/jboss/logging/util CategoryStream.java
CategoryWriter.java package.html
Log:
o moved non-service logging components to common
o moved Cat* to org.jboss.logging.util
o renamed TracePriority to XPriority as this class provides the
ability to hold other extention priorites.
Revision Changes Path
1.1 jboss-common/src/main/org/jboss/logging/util/CategoryStream.java
Index: CategoryStream.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss.logging.util;
import java.io.IOException;
import java.io.PrintStream;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
/**
* A subclass of PrintStream that redirects its output to a log4j Category.
*
* <p>This class is used to map PrintStream/PrintWriter oriented logging onto
* the log4j Categories. Examples include capturing System.out/System.err
* writes.
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>.
* @version $Revision: 1.1 $
*/
public class CategoryStream
extends PrintStream
{
private Category category;
private Priority priority;
private boolean inWrite;
private boolean issuedWarning;
/**
* Redirect logging to the indicated category using Priority.INFO
*/
public CategoryStream(final Category category)
{
this(category, Priority.INFO, System.out);
}
/**
* Redirect logging to the indicated category using the given
* priority. The ps is simply passed to super but is not used.
*/
public CategoryStream(final Category category,
final Priority priority,
final PrintStream ps)
{
super(ps);
this.category = category;
this.priority = priority;
}
public void println(String msg)
{
if( msg == null )
msg = "null";
byte[] bytes = msg.getBytes();
write(bytes, 0, bytes.length);
}
public void println(Object msg)
{
if( msg == null )
msg = "null";
byte[] bytes = msg.toString().getBytes();
write(bytes, 0, bytes.length);
}
public void write(byte b)
{
byte[] bytes = {b};
write(bytes, 0, 1);
}
public synchronized void write(byte[] b, int off, int len)
{
if( inWrite == true )
{
// There is a configuration error that is causing looping. Most
// likely there are two console appenders so just return to prevent
// spinning.
if( issuedWarning == false )
{
String msg = "ERROR: invalid console appender config detected,
console stream is looping";
try
{
out.write(msg.getBytes());
}
catch(IOException ignore) {}
issuedWarning = true;
}
return;
}
inWrite = true;
// Remove the end of line chars
while( len > 0 && (b[len-1] == '\n' || b[len-1] == '\r') && len > off )
len --;
// HACK, something is logging exceptions line by line (including
// blanks), but I can't seem to find it, so for now just ignore
// empty lines... they aren't very useful.
if (len != 0) {
String msg = new String(b, off, len);
category.log(priority, msg);
}
inWrite = false;
}
}
1.1 jboss-common/src/main/org/jboss/logging/util/CategoryWriter.java
Index: CategoryWriter.java
===================================================================
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/
package org.jboss.logging.util;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
/**
* A subclass of PrintWriter that redirects its output to a log4j Category. <p>
*
* This class is used to have something to give api methods that require a
* PrintWriter for logging. JBoss-owned classes of this nature generally ignore
* the PrintWriter and do their own log4j logging.
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a>
* .
* @created August 19, 2001
* @version $$
*/
public class CategoryWriter
extends PrintWriter {
private Category category;
private Priority priority;
private boolean inWrite;
private boolean issuedWarning;
/**
* Redirect logging to the indicated category using Priority.INFO
*
* @param category Description of Parameter
*/
public CategoryWriter( final Category category ) {
this( category, Priority.INFO );
}
/**
* Redirect logging to the indicated category using the given priority. The
* ps is simply passed to super but is not used.
*
* @param category Description of Parameter
* @param priority Description of Parameter
*/
public CategoryWriter( final Category category,
final Priority priority ) {
super( new InternalCategoryWriter( category, priority ), true );
}
/**
* @created August 19, 2001
*/
static class InternalCategoryWriter extends Writer {
private Category category;
private Priority priority;
private boolean closed;
public InternalCategoryWriter( final Category category, final Priority
priority ) {
lock = category;
//synchronize on this category
this.category = category;
this.priority = priority;
}
public void write( char[] cbuf, int off, int len )
throws IOException {
if ( closed ) {
throw new IOException( "Called write on closed Writer" );
}
// Remove the end of line chars
while ( len > 0 && ( cbuf[len - 1] == '\n' || cbuf[len - 1] == '\r' ) ) {
len--;
}
if ( len > 0 ) {
category.log( priority, String.copyValueOf( cbuf, off, len ) );
}
}
public void flush()
throws IOException {
if ( closed ) {
throw new IOException( "Called flush on closed Writer" );
}
}
public void close() {
closed = true;
}
}
}
1.1 jboss-common/src/main/org/jboss/logging/util/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<!-- $Id: package.html,v 1.1 2002/02/24 10:16:53 user57 Exp $ -->
<!--
JBoss: The OpenSource J2EE WebOS
Distributable under LGPL license.
See terms of license at gnu.org.
-->
</head>
<body bgcolor="white">
<p>Logging utilties and helpers.
<h2>Package Specification</h2>
<ul>
<li><a href="javascript: alert('not available')">Not Available</a>
</ul>
<h2>Related Documentation</h2>
<ul>
<li><a href="javascript: alert('not available')">Not Available</a>
</ul>
<h2>Package Status</h2>
<ul>
<li><font color="green"><b>STABLE</b></font>
</ul>
<h2>Todo</h2>
<ul>
<li>???
</ul>
<!-- Put @see and @since tags down here. -->
</body>
</html>
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development