-1

I have a problem with java.util.logging. I'm telling you.

I have my program in a jar file and when I run it, logging works as I hope. In this case I load the logging configuration in the main method.

But, if I run from a different jar logging doesn't work with the configuration, but with the logging default configuration. I didn't set a logging configuration previously. Logging applies the java.util.logging.FileHandler.pattern, but it doesn't apply the java.util.logging.FileHandler.formatter class. In this new jar, I load other jars adding them with ClassLoader.

The configuration file is:

handlers = java.util.logging.FileHandler

.level = FINER
java.util.logging.FileHandler.level = FINER
java.util.logging.FileHandler.formatter = gx.util.logging.FormatoDesarrollo2
java.util.logging.FileHandler.pattern = log-client-%g.txt

java.util.logging.ConsoleHandler.level = FINER
java.util.logging.ConsoleHandler.formatter = gx.util.logging.FormatoDesarrollo2

gx.games.level=WARNING

Then, where is the problem?

Thank you, very much.

Fran1234
  • 1
  • 1

1 Answers1

0

In this new jar, I load other jars adding them with ClassLoader.

This seems suspect. Can you include code in your questions around this? The LogManager searches the system class path:

Note that all classes loaded during LogManager configuration are first searched on the system class path before any user class path. That includes the LogManager class, any config classes, and any handler classes.

Even though the docs say it will search the user class path that is not true for handlers or formatters. Of note is: JDK-6878454 LogManager class loading inconsistent with Java EE best practices

Since your are adding jars make sure your formatter is on the system class path. One way to test this is to add the following:

Class.forName("gx.util.logging.FormatoDesarrollo2", true, ClassLoader.getSystemClassLoader());

If that throws ClassNotFoundException then you have an issue with your ClassLoader layout.

You have two options if that is the case:

  1. Place the formatter on the system class path.
  2. Use the java.util.logging.config.class option as that will fallback to the Thread::getContextClassLoader
jmehrens
  • 10,580
  • 1
  • 38
  • 47