Rich,
I extended PrintStream to accept a Logger and priority on the constructor.
The write(String) and print(Object) methods are overriden to call log4j.
All other methods are overriden to call one of those 2.  I extended log4j
configuration to accept a property, if set to true then:

      System.setOut(new Log4JPrintStream(Logger.getLogger("System.Out"),
Priority.NORMAL));
      System.setErr(new Log4JPrintStream(Logger.getLogger("System.Err"),
Priority.ERROR));

You'll need a "NullOutputStream" object to pass to the constructor of
PrintStream during the super call in the Log4JPrintStream constructor.  It
overrides OutputStream methods with no-ops.

This works for any appender and in your case will definitely roll when it
should.  Only drawbacks are formatting when making multiple calls to
System.out and expecting it to be 1 message, but then again you probably
have that issue now.

Chris



                                                                                       
                                            
                      Rich Gibbs                                                       
                                            
                      <rich.gibbs@enhan        To:       "Log4j-Dev (E-mail)" 
<[EMAIL PROTECTED]>                       
                      siv.com>                 cc:                                     
                                            
                                               Subject:  Rolling appender, that 
contains standard err/out                          
                      12/04/2002 02:41                                                 
                                            
                      PM                                                               
                                            
                      Please respond to                                                
                                            
                      "Log4J Developers                                                
                                            
                      List"                                                            
                                            
                                                                                       
                                            
                                                                                       
                                            




Has anyone come across the need to be able to have the standard streams of
stdout, and stderr go to a rolling logfile?

I played with extending the rollinglog appender, and have a working
version.
I'm not completly happy in that it will only roll, when logging is done to
a
category, but the size is incremented for standard streams, so as long as
atleast some of the logging goes to a category, the logs will roll
properly,
or atleast reasonably...






--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to