Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > loggers with different handler properties

Reply
Thread Tools

loggers with different handler properties

 
 
Simo-Pekka Sadeluoto
Guest
Posts: n/a
 
      07-08-2003
I have two java.util.logging.Loggers that both should use the same
Handler class but with different properties. How should I configure this
using my own properties defined with java.util.logging.config.file?

My current properties file has something like this (unimportant stuff
stripped out):

handlers = java.util.logging.FileHandler
java.util.logging.FileHandler.pattern = /tmp/a_%u.log
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

But what I would like to do is use two Loggers that write stuff to
different files with different Formatters. Or to be exact, I have
written my own Handler and Formatter implementations, but let's not make
it too complicated. My code looks like this:

Logger a = Logger.getLogger("a");
Logger b = Logger.getLogger("b");
a.log(Level.INFO, "test a");
b.log(Level.INFO, "test b");

But how do I tell to logger b that it should use FileHandler with
pattern "/tmp/b_%u.log" and SimpleFormatter? Now both use FileHandler
properties defined in the properties file. Of course I could hard-code
it like this:

Handler h = new FileHandler("/tmp/b_%u.log");
h.setFormatter(new SimpleFormatter());
b.addHandler(h);
b.setUseParentHandlers(false); // nothing to /tmp/a_%u.log

All I loose this way is the flexibility! I also tried adding facility
specific properties like this to configuration:

b.pattern = /tmp/b_%u.log
b.formatter = java.util.logging.SimpleFormatter

But this does not affect the behaviour of Logger b at all. And how could
it, pattern and formatter are properties of Handler and not of Logger.
Have they really not thought of this, all the examples I found only set
..level per facility!

--
http://www.velocityreviews.com/forums/(E-Mail Removed) "The more things change the more they suck!"
http://www.iki.fi/sipe/ - Butthead
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic Question about Loggers, Parent Loggers, and Levels Rhino Java 8 04-30-2010 10:20 PM
Loggers and reloads Francois Bouffard Python 2 05-27-2004 04:22 AM
Re: Key Loggers Brad Computer Security 0 04-09-2004 12:08 PM
Re: Key Loggers Brad Computer Security 0 04-09-2004 11:35 AM
Key Loggers Brad Computer Security 3 04-07-2004 10:21 PM



Advertisments