User: user57
Date: 01/07/06 17:49:34
Modified: src/main/org/jboss/logging/log4j CategoryStream.java
Log:
o write() will not log messages that are empty. something is logging
exceptions (including blank lines), but I can't find out what is doing
it, so for now just don't log stuff with empty messages.
Revision Changes Path
1.5 +41 -24 jboss/src/main/org/jboss/logging/log4j/CategoryStream.java
Index: CategoryStream.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/log4j/CategoryStream.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CategoryStream.java 2001/06/18 20:01:27 1.4
+++ CategoryStream.java 2001/07/07 00:49:34 1.5
@@ -12,35 +12,46 @@
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
-/** A subclass of PrintStream that redirects its output to a log4j Category.
-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.4 $
-*/
-public class CategoryStream extends PrintStream
+/**
+ * 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.5 $
+ */
+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(Category category)
+ /**
+ * 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(Category category, Priority priority, PrintStream ps)
+
+ /**
+ * 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 )
@@ -48,6 +59,7 @@
byte[] bytes = msg.getBytes();
write(bytes, 0, bytes.length);
}
+
public void println(Object msg)
{
if( msg == null )
@@ -55,40 +67,45 @@
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.
- */
+ // 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 e)
- {
}
+ 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 --;
- String msg = new String(b, off, len);
- category.log(priority, msg);
+ // 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;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development