The build file called using <ant> task resets the logging configs of the caller
Asked Answered
O

1

7

Two projects: the product (project-A) and the auto benchmark project for A (project-B).

In B's build file, we need to call A's build file to run the build and bundle-with-app-server process like this:

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

And, in project B, we have a lot of Ant tasks that output messages using java.util.logging (The JDK Logging Framework).

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

With debugging, I find that, during the initialzation of project A's build file, a staticly defined thing in project A will run LogManager.readConfiguration(InputStream), which loads a config file that only contains the logger configuration of a single class.

And during readConfiguration, LogManager.reset() will be called; during reset, each handler of each logger will be removed. As <ant> will load the target build file to the same process of the caller, all the handlers will be removed.

So, except the configurated one, every other class that use jdk logger can't output messages due to lack of output handler.

My question is:

Is there any way to solve this problem, other than:

  1. use <exec> to run project A's build file;
  2. write a task to run readConfiguration() to restore the default JDK logging settings from the default configuration file after the <ant> call.
  3. Use ant's own logging framework (Task.log(), etc).

Please note that I can't modify project A to prevent the problem.

Offprint answered 18/7, 2013 at 8:42 Comment(6)
What do you mean by "disappear" exactly?Sideboard
@Sideboard Output of jdk logger doesn't show up in the console -- the task is successfully executed, but no output. As I said, the ConsoleHandler of the root logger is removed when readConfiguration(InputStream), which formats and outputs the logging message.Offprint
Is the Ant tasks they are making use of JDK logging or the targets that you have defined execute Java programs which does logging?Karalynn
<ant> task loads the build file into the same JVM, as another project. And, readConfiguration affects all the existing JDK loggers inside that JVM. The best way I can think of is to run the other build file in a seperate JVM, but <exec> task may cause problem when there are multiple installs of JDK and Ant in the OS.Offprint
I think but not sure that you can check by having inheritall="false" either be removed or make it true. Just check that.Ade
A SSCCE would be very helpful and may attract more answers.Treblinka
C
2

You might be able to create subclass of LogManager and override reset and the two readConfiguration methods to install the handlers you need. Then use the java.util.logging.config.class system property to install your custom code on statup.

Curd answered 26/7, 2013 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.