javaloggingglassfishglassfish-4java.util.logging

SimpleFormatter ignoring the java.util.logging.SimpleFormatter.format property


I'm using java.util.logging on GlassFish 4.

I'm defining my own class to initialize the LogManager by defining the System property: -Djava.util.logging.config.class.

My class loads the logging.properties file, merges it with some other property file and does some custom replacement.

The following is the relevant part of my logging.properties file:

java.util.logging.FileHandler.pattern=C:/Work/server/glassfish/domains/domain1/logs/JMSFileHandler%g.log
java.util.logging.FileHandler.limit=2000000
java.util.logging.FileHandler.count=20
java.util.logging.FileHandler.append=true
java.util.logging.FileHandler.level=ALL
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%1$tY:%1$tm:%1$td %1$tH:%1$tM:%1$tS|%4$s: %2$s%n%5$s%n%6$s%n

I'm using the standard FileHandler and configuring it to use the SimpleFormatter as the formatter.

But the java.util.logging.SimpleFormatter.format String is being totally ignored. Instead SimpleFormatter uses its default format.

Where did I go wrong?


Solution

  • I was assuming that the System Property java.util.logging.config.file is set by GF from the beginning. This is not the case.

    After some investigation I realized that the LogManager is initialized two times. In the first time that property doesn't exist, the second time it does.

    I was getting an error on the first initialization because I was counting on that property, therefore I didn't initialize the LogManager properly, causing the SimpleFormatter to use the default format.

    I fixed this by changing my code and no longer counting on that System property. This solved the issue.

    GF still sets the System property java.util.logging.config.file later.