• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reformatting standard out in a logging class

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java n00b here...

i've got a piece of code that demonstrates simple logging using a custom format,
which looks like this:


SEVERE 27 Aug 04 1311:26.790 my severe message
WARNING 27 Aug 04 1311:26.800 my warning message
INFO 27 Aug 04 1311:26.801 my info message



Though I'm not sure how/why, the application also prints to standard out:


Aug 27, 2004 1:10:43 PM LoggerTest main
SEVERE: my severe message
Aug 27, 2004 1:10:43 PM LoggerTest main
WARNING: my warning message
Aug 27, 2004 1:10:43 PM LoggerTest main
INFO: my info message



My goal is to have standard out look the same as the logfile itself. But as I
said, I don't even know where standard out is being written to.
java.util.logging.Logger doesn't print anything out.

All help very much appreciated!







Above code modified from: http://javaalmanac.com/egs/java.util.logging/CustomFormat.html
[ August 27, 2004: Message edited by: Harry Slaughter ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It prints to standard out (actually standard error, I think) because that is the parent of the logger you have defined. You can turn off logging to the parent by calling

or you can set the formatter on the parent logger by calling

This will set the formatter for the first handler on the parent, but unless you've actually added others, I believe there will always only be one.

Hope that helps.

Derek
 
Harry Slaughter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wow, i don't understand it (yet), but it sure works. now i'm going to try to understand why.

i'm still having trouble replacing my procedural thinking with OO thinking

thanks a lot
reply
    Bookmark Topic Watch Topic
  • New Topic