You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Will Wood <Wi...@wnco.com> on 2002/01/08 15:29:43 UTC

Issue with ConsoleAppender and FileAppender in general.

** High Priority **

We're using 1.1.3 and have hit upon an issue when using the FileAppender or ConsoleAppender.  
If we use the no argument Constructors for FileAppender or ConsoleAppender and then
set the Layout and either File or Target for the respective appender we get an error

log4j:ERROR No output stream or file set for the appender

Even though the Target (for ConsoleAppender) or File (for FileAppender is set.)

If we use the Argument based Constructor, it works.

Any Ideas??

Attached is a sample that shows the problem

import org.apache.log4j.*;

public class Bug
{

    public static void main(String[] args)
    {
		Category c = Category.getRoot();
		c.removeAllAppenders();

		PatternLayout l = new PatternLayout("%p %t %C:%M %m%n");

		ConsoleAppender app = new ConsoleAppender();
		app.setLayout(l);
		app.setTarget(ConsoleAppender.SYSTEM_OUT);

		c.addAppender(app);

		c.error("Test."); // fails with "log4j:ERROR No output stream or file set for the appender named [null].

		c.removeAllAppenders();

		c.addAppender(new ConsoleAppender(l, ConsoleAppender.SYSTEM_OUT));

		c.error("Test again."); // works.

    }
}


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Issue with ConsoleAppender and FileAppender in general.

Posted by Tory Toupin <to...@yahoo.com>.
 
You need to call activateOptions() after setting the properties for them to take effect (in your code, right before the call to addAppender).
  Will Wood <Wi...@wnco.com> wrote: ** High Priority **

We're using 1.1.3 and have hit upon an issue when using the FileAppender or ConsoleAppender. 
If we use the no argument Constructors for FileAppender or ConsoleAppender and then
set the Layout and either File or Target for the respective appender we get an error

log4j:ERROR No output stream or file set for the appender

Even though the Target (for ConsoleAppender) or File (for FileAppender is set.)

If we use the Argument based Constructor, it works.

Any Ideas??

Attached is a sample that shows the problem

import org.apache.log4j.*;

public class Bug
{

public static void main(String[] args)
{
Category c = Category.getRoot();
c.removeAllAppenders();

PatternLayout l = new PatternLayout("%p %t %C:%M %m%n");

ConsoleAppender app = new ConsoleAppender();
app.setLayout(l);
app.setTarget(ConsoleAppender.SYSTEM_OUT);

c.addAppender(app);

c.error("Test."); // fails with "log4j:ERROR No output stream or file set for the appender named [null].

c.removeAllAppenders();

c.addAppender(new ConsoleAppender(l, ConsoleAppender.SYSTEM_OUT));

c.error("Test again."); // works.

}
}


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



---------------------------------
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail.