Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure the properties of a specific FileHandler

The Java logging configuration file lets me define the properties of a named logger, e.g.

name.heikoseeberger.heikotron.level = FINE
name.heikoseeberger.heikotron.handlers = java.util.logging.FileHandler

So far, so good. Now I would like to configure that particular FileHandler, e.g. with a specific output file. Unfortunately I only know how to configure the "global" FileHandler, which is already present in the configuration file:

java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

I don't want to configure this one, but the instance which is associated with my custom Logger. I already tried the following, but without success:

name.heikoseeberger.heikotron.java.util.logging.FileHandler.pattern = %h/heikotron.log
name.heikoseeberger.heikotron.java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

Is it possible at all to set the properties of specific FileHandler instances? If yes, how should these be identified/named?

like image 416
Heiko Seeberger Avatar asked May 10 '12 10:05

Heiko Seeberger


1 Answers

This is done by using the config option described in the top level class documentation of the LogManger. Create a public named class with a public constructor and invoke all of the java calls you need to make to configure your handler. Then in your logging properties direct the LogManager to load your class you created to configure your handler. Otherwise you can to subclass file handler which will create a custom namespace to configure.

like image 192
jmehrens Avatar answered Sep 29 '22 17:09

jmehrens