• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Logging file

Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am using the java.util.logging to log my messages to log file, as well as showing in the console, eventhough this is not required. I am having one log file for each class. But I would like to have one log file only, and I think I should have one kind of global logger and/or handler. Can anyone tell me please? I am doing something like this for each class:
private static Logger logger = Logger.getLogger (suncertify.client.LocalClient.class.getName());
private static FileHandler fh;
fh = new FileHandler("mylog%u.%g.log", true);
and I have as a result:
each log file is for one of my classes. Now if I want it globally, where do I create the logger, and how does it look like?

Thank you very much.........
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you could simply configure you logger properties in the logging.properties file in the lib directory of your JRE.

Or configure it in a new file and use the


to set up the file in your program.

If you JDK is installed in /opt/jdk then the default logging.properties file should be located in /opt/jdk/jre/lib.

Take a look at this file, it contains a lot of information about how to configure a logger.

You could also read the Logging Overview in the JDK help.

If you insist in doing this in code, set the FileHandler for the higher logger in the hierachy instead of setting the handler for every class that has a logger.

For instance, if your package hierachy is suncertify.db then declare a static logger for the package suncertify and add the handler to it.

Since loggers work in a hierachy, all the classes using a logger whose name is within this hierachy will use that file handler also. That you will learn in the Logging Overview in the JDK.
[ December 15, 2006: Message edited by: Edwin Dalorzo ]
    Bookmark Topic Watch Topic
  • New Topic