RE: Rolling appender, that contains standard err/out

2002-12-05 Thread Ceki Gülcü
At 19:24 05.12.2002 -0800, Rich Gibbs wrote:


I just came across this in the 1.2.7 release similar code ran without a
problem in the 1.0.2 release I believe...


[snip]


log4j.rootCategory=WARN, stdout  <-- watch the WARN level


Do you think the level setting is right? :-)


--
Ceki



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: Rolling appender, that contains standard err/out

2002-12-05 Thread Rich Gibbs


I just came across this in the 1.2.7 release similar code ran without a
problem in the 1.0.2 release I believe...

The output is as follows:

0 [main] INFO testing.Main  - The log object is org.apache.log4j.Logger
10 [main] INFO testing.Main  - Starting main()
10 [main] INFO testing.Main  - init(1)...


It seems that calling the PropertyConfigurator with a String, or just
properties after some categories are initialized, causes the initial
categories to not print any longer. 

Any ideas?  I looked through the bug database, but I did not see anything
that looked related...

Thanks

Rich 

package testing;

import org.apache.log4j.*;

/**
 *
 * Test Basic initialization, prior to initializing based on a specific
 * application file.
 */
public class Main {

/*
 * The category to be used in this class for testing purposes...
 * In the real life example, the category at this level is static
and initialized
 * here.  Additonal categories are initialized for every class, but
the
 * actual properties path can't be determined till later, at which
point it
 * needs to be used.
 */
private static Category log;

static
{

BasicConfigurator.configure();


log = Category.getInstance(Main.class );
log.info("The log object is " + log.getClass().getName());

}
public static void main(String[] args) {
log.info( "Starting main()" );

Main m = new Main();

m.init();

log.info( "Still works" );
}



private void init()
{

  log.info( "init(1)..." );
  Category log2 = Category.getInstance(Main.class);


  String logPropertiesPath = "J:\\log4jTesting\\log.properties";
  PropertyConfigurator.configure(logPropertiesPath);
  log.info( "init(2)..." );
  
  log.info( "does log still work?" );




PropertyConfigurator.configureAndWatch( logPropertiesPath );
log.debug( "3 logPropertiesPath(realPath)=" + logPropertiesPath );
}
}

The contents of the log.properties file...

log4j.rootCategory=WARN, stdout
#log4j.debug=true
# stdout is set to be a ConsoleAppender.

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#log4j.appender.stdout=org.apache.log4j.FileAppender
#log4j.appender.stdout.File=System.out

# stdout uses PatternLayout.
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n

#struts debugging
log4j.category.org.apache.struts=WARN

#enhansiv debugging
log4j.category.com.enhansiv=DEBUG



RE: Rolling appender, that contains standard err/out

2002-12-04 Thread Chris . Nokes

I built it on top of 1.1.3, but I see no reason why it wouldn't work with
any version.


Chris




   

  Rich Gibbs   

  
  siv.com> cc: 

   Subject:  RE: Rolling appender, that 
contains standard err/out  
  12/04/2002 03:47 

  PM   

  Please respond to

  "Log4J Developers

  List"

   

   





Actually, I avoided the formatting issue, by writing directly to the lower
level stream, which is why the rolling which is detected at the higher
level
does not work exactly as desired.

What version is your extension in?  I was just working with the 1.2.7
base...

Thanks

Rich Gibbs

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 04, 2002 1:42 PM
To: Log4J Developers List
Cc: Log4j-Dev (E-mail)
Subject: Re: Rolling appender, that contains standard err/out



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







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




RE: Rolling appender, that contains standard err/out

2002-12-04 Thread Rich Gibbs
Actually, I avoided the formatting issue, by writing directly to the lower
level stream, which is why the rolling which is detected at the higher level
does not work exactly as desired.

What version is your extension in?  I was just working with the 1.2.7
base...

Thanks

Rich Gibbs

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 04, 2002 1:42 PM
To: Log4J Developers List
Cc: Log4j-Dev (E-mail)
Subject: Re: Rolling appender, that contains standard err/out



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




Re: Rolling appender, that contains standard err/out

2002-12-04 Thread Chris . Nokes

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   

 
  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:   
For additional commands, e-mail: