• Post Reply Bookmark Topic Watch Topic
  • New Topic

**Major** problem with logging and System.err  RSS feed

 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is what I did. By default the ConsoleHandler goes to System.err. I did not want this. I wanted it to go to System.out. So I created my own class that extends ConsoleHandler. In the constructor of my class I call setOutputStream(System.out);. Now here's the weird problem. After making the call to setOutputStream(System.out); now System.err.println("") **DOESN'T WORK!** I have no idea where the System.err output is going but it's no longer going to the console!
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well.... I've never used ConsoleHandler, but according to the API, it says:

"This Handler publishes log records to System.err."

-- so I don't know if you can redirect it to System.out.....
[ November 21, 2004: Message edited by: Jessica Sant ]
 
Patrick Hooper
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be curious to know if there was a way to shut off the output to stderr. I'm outputting a simple format message to a log file but still getting the output to stderr. I'm using a filehandler for the log file output.

Thank you in advance.
 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you'd want to do is take a look at the Logger API and do
logger.setUseParentHandlers(false); I think that'll do what you want. It'll only use your filehandler and not pass the log message up to the parents. After getting an instance of a Logger object I also use the getHandlers() and removeHandler() methods to get rid of any handlers I didn't put there.

Originally posted by Patrick Hooper:
I'd be curious to know if there was a way to shut off the output to stderr. I'm outputting a simple format message to a log file but still getting the output to stderr. I'm using a filehandler for the log file output.

Thank you in advance.
 
Patrick Hooper
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perfect Michael. Thank you very much for the tip. I looked over the API but obviously didn't understand everything I was looking at.

Patrick
 
Vidur rAI
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,

Were you able to solve your initial problem? I.e

"Now here's the weird problem. After making the call to setOutputStream(System.out); now System.err.println("") **DOESN'T WORK!** I have no idea where the System.err output is going but it's no longer going to the console!"

I would like to know how your resolved it.

thank you,

vidurrai@yahoo.com
 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never did resolve it, sorry. I am aware of the issue and just try not to get into that situation.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you guys read the Javadoc for "setOutputStream"?


protected void setOutputStream(OutputStream out)
throws SecurityException

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.


Once you've closed System.err, you can't write to it anymore! Because PrintStream's methods don't throw exceptions, the failure is silent.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!