OO related question
Hi,
If I have the following code:
class SystemOutConsoleHandler extends ConsoleHandler {
/**
*
* Creates a new instance.
*/
SystemOutConsoleHandler() {
super();
setOutputStream(System.out);
setLevel(Level.ALL);
setFilter(new Filter() {
public boolean isLoggable(final LogRecord record) {
// only log infos and fine messages
return record.getLevel().intValue() <= Level.INFO
.intValue();
}
});
}
}
According javadoc:
setOutputStream(OutputStream stream);
Change the output stream.
If there is a current output stream then the Formatter's tail string
is written and the stream is flushed and closed. Then the output
stream is replaced with the new output stream.
The above code will close my Std error. And create a new output stream
and old output stream is not closed.
But the code below fixes the problem. Why? Educate me please.
cheers,
//mike
class SystemOutConsoleHandler extends ConsoleHandler {
/**
*
* Creates a new instance.
*/
SystemOutConsoleHandler() {
super();
setLevel(Level.ALL);
setFilter(new Filter() {
public boolean isLoggable(final LogRecord record) {
// only log infos and fine messages
return record.getLevel().intValue() <= Level.INFO
.intValue();
}
});
}
protected synchronized void setOutputStream(OutputStream out)
throws
SecurityException {
super.setOutputStream(System.out);
}
}