logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Nyolt <a31bd...@freenet.de>
Subject Re: Log4j closes System.err
Date Mon, 28 Feb 2011 10:41:48 GMT
No idea, anyone?
Appearently, this has to work somehow, since using a configuration file you can set the follow-option
to be true without closing any stream.
But I never found any hint how to do this.

Am 18.02.2011 15:01, schrieb Martin Nyolt:
> Hello,
>
> I use the following code to load a default configuration in case no configuration was
set using the log4j.configuration property:
>
> static {
> LOGGER = Logger.getLogger(MyClass.class);
> Logger root = Logger.getRootLogger();
> boolean inited = root.getAllAppenders().hasMoreElements();
>
> if (!inited) {
> Layout layout = new PatternLayout("%-5p [%t]: %m%n");
> // create Appender to System.err
> ConsoleAppender app = new ConsoleAppender(layout, ConsoleAppender.SYSTEM_ERR);
> // set the follow option
> app.setFollow(true);
> app.activateOptions();
> root.addAppender(app);
> root.setLevel(Level.ERROR);
> }
> }
>
> If I don't call "app.activateOptions()", the follow-option wouldn't take effect (and
I do need "follow" to be true).
> But activateOptions finally calls WriterAppender.reset, which calls ConsoleAppender.close
and closes the previous output stream, in this case System.err - but closing System.err is
not a good idea, as it is still needed - I just want to change the Follow-Option.
>
> Is this a misbehaviour of log4j, or am I incorrectly using the API?
>
> Best regards
> Martin Nyolt


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message