The assembly file, called with the <ant> command, resets the caller's logging configuration

Two projects: a product (project-A) and a self-test project for A (project-B).

In assembly file B, we need to call the assembly file to start the assembly and assembly process using the server application as follows:

<ant antfile="${build-file-A}" inheritall="false" target="all" /> 

And in project B, we have many Ant tasks that print messages using java.util.logging (The JDK Logging Framework).

The problem is that after this line all the outputs of the jdk logger disappear.

When debugging, I found that during the initialization of the project A assembly file, the statically set thing in project A will start LogManager.readConfiguration(InputStream) , which loads a configuration file that contains only the registrar configuration for one class.

And during readConfiguration LogManager.reset() will be called; during reset , each handler of each registrar will be deleted . Since <ant> loads the target assembly file into the same process of the caller, all handlers will be deleted.

Thus, with the exception of the configured one, every other class that uses the jdk logger cannot output messages due to the lack of an output handler.

My question is:

Is there any way to solve this problem besides:

  • use <exec> to run the project build file;
  • write the task to run readConfiguration() to restore the default JDK maintenance settings from the default configuration file after calling <ant> .
  • Use Ant's own logging structure (Task.log (), etc.).

Please note that I cannot modify project A to prevent the problem.

+6
source share
1 answer

You may be able to subclass LogManager and override reset and the two readConfiguration methods to set the handlers you need. Then use the java.util.logging.config.class system property to set your code to statup.

+1
source

Source: https://habr.com/ru/post/949724/


All Articles