How to set properties of a specific FileHandler

The Java log configuration file allows me to define the properties of a named logger, for example

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, for example. with a specific output file. Unfortunately, I 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 do not want to configure this, but the instance associated with my own Logger. I have already tried the following, but to no avail:

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 even possible to set the properties of specific instances of FileHandler? If so, how to identify / name them?

+5
source share
3 answers

config, LogManger. java, . LogManager . , .

+1

, . FileHandler, , "java.util.logging.FileHandler.pattern ", ,

private void configure() {
        LogManager manager = LogManager.getLogManager();

        String cname = getClass().getName();

        pattern = manager.getStringProperty(cname + ".pattern", "%h/java%u.log");
        limit = manager.getIntProperty(cname + ".limit", 0);
        //...
    }

, , , .

, - (.. name.heikoseeberger.heikotro n), , LogRecord.

, LogManager, , , , , , , .

0

, java.util.logging. .

If you cannot switch to another logging structure, such as Logback , check out the answer to java util logging.properties: How to connect to two different files and see if it suits your needs.

0
source

All Articles