• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

java.util.logging question

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public static void main(String[] args) {
Logger log = Logger.getLogger(Test.class.getName());
ConsoleHandler h = new ConsoleHandler();
h.setFormatter(new SimpleFormatter());
log.addHandler(h);
log.info("Test");
}


Has the following output:


May 23, 2006 4:24:10 PM com.dmotorworks.lib.clie.Test main
INFO: Test
May 23, 2006 4:24:10 PM com.dmotorworks.lib.clie.Test main
INFO: Test


Why is it printing TWICE?
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default logging configuration already provides a Console Handler. Then you are adding another one. That�s why it is printed twice.

If you do not add another handler it will be printed just once.

The default logging configuration is stored in the jre\lib\logging.properties file.

It is a better idea if you set up your loggin handler from this file or create a new file and set it using the -Djava.util.logging.config.file=myfile command line property, as specified in the default logging configuration file.

I hope this helps!
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic