custom java.util.logging properties file resulting in duplicate log files

1.6k views Asked by At

I'm running a stand-alone Jenkins server launched from the WAR file. Jenkins advertises itself as using the java.util.logging framework for logging. I launch it as follows:

java -Djava.util.logging.config.file=mycustomlogging.properties -jar jenkins.war > jenkins.log

mycustomlogging.properties contains the following:

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=WARNING
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

What I expected is for all logging to go into jenkins.log and for only WARNING messages and above to be logged.

The contents of jenkins.log are as expected, but I'm also seeing a file ~/java0.log created that contains XML-formatted log statements at INFO and above.

Why is java0.log being created when I only specify a ConsoleHandler (and no FileHandler) in mycustomlogging.properties?

Is my properties file being "merged" with the default system one, which (presumably) configures a FileHandler writing to ~/java0.log? My expectation was that specifying a custom properties file would completely override the default system behavior.

Or is it likely the server code is written such that it ignore the system properties and just logs to ~/java0.log "no matter what"?

If it matters, I'm on OS X 10.10 using Java 7.

1

There are 1 answers

0
jmehrens On

Why is java0.log being created when I only specify a ConsoleHandler (and no FileHandler) in mycustomlogging.properties?

It is possible your properties file was never found or the configuration was thrown out by code performing a LogManager.reset() or LogManager.readConfiguration(InputStream).

Is my properties file being "merged" with the default system one, which (presumably) configures a FileHandler writing to ~/java0.log?

A merge is not possible with the default LogManager. There has to be code that is directly creating and adding the FileHandler.

Or is it likely the server code is written such that it ignore the system properties and just logs to ~/java0.log "no matter what"?

Yes. LogManager.reset will throw out your configuration.

Try to configure a Groovy Hook Script to call LogManager.reset() and then install your ConsoleHandler. This is described in the Jenkins logging wiki.