User: starksm 
  Date: 01/06/15 14:54:20

  Modified:    src/main/org/jboss/logging/log4j CategoryStream.java
                        ConsoleAppender.java
  Log:
  Add check to prevent invalid console appender configurations from
  creating infinite looping.
  Add NDC.push()/NDC.pop() usage in the Log setLog()/unsetLog() methods
  
  Revision  Changes    Path
  1.3       +40 -4     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CategoryStream.java       2001/05/22 22:12:57     1.2
  +++ CategoryStream.java       2001/06/15 21:54:20     1.3
  @@ -6,6 +6,7 @@
    */
   package org.jboss.logging.log4j;
   
  +import java.io.IOException;
   import java.io.PrintStream;
   
   import org.apache.log4j.Category;
  @@ -16,12 +17,14 @@
   the log4j Categories. Examples include capturing System.out/System.err writes.
   
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.2 $
  +@version $Revision: 1.3 $
   */
   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
       */
  @@ -40,19 +43,52 @@
       }
       public void println(String msg)
       {
  -        category.log(priority, msg);
  +        if( msg == null )
  +            msg = "null";
  +        byte[] bytes = msg.getBytes();
  +        write(bytes, 0, bytes.length);
       }
       public void println(Object msg)
       {
  -        category.log(priority, 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 void write(byte[] b, int off, int len)
  +    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 e)
  +                {
  +                }
  +                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);
  +        inWrite = false;
       }
   }
  
  
  
  1.2       +2 -2      jboss/src/main/org/jboss/logging/log4j/ConsoleAppender.java
  
  Index: ConsoleAppender.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/logging/log4j/ConsoleAppender.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConsoleAppender.java      2001/05/11 02:50:29     1.1
  +++ ConsoleAppender.java      2001/06/15 21:54:20     1.2
  @@ -19,7 +19,7 @@
   system via a category named Default.
   
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@version $Revision: 1.2 $
   */
   public class ConsoleAppender extends AppenderSkeleton
   {
  @@ -61,8 +61,8 @@
       {
           String msg = this.layout.format(event);
           if( event.priority == Priority.ERROR )
  -            out.print(msg);
  -        else
               err.print(msg);
  +        else
  +            out.print(msg);
       }
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to