1

I have a servlet running in Tomcat on a server. One of the tasks the servlet does is transform documents using a translation library jar. Executing a java -jar "..." command.

I use log4j to log the actions a sample below.

[echo] [init] Initialize build space 
[echo] build.web.dir= /home/scott/workspace/mbel-work/tei2html/build/web teiFile=A10007 docName=A10007.xml
[echo] [tei-doc-to-html] Building html documents production=no
[echo] "/home/scott/workspace/mbel-work/tei2html/build/web/A10007/A10007.html is up to date!"
[echo] [tei-to-html] Build index.html, searchsite.html and solrsearch.html files

I upgraded java and now I see this.

[echo] [init] Initialize build space 
[echo] build.web.dir= /home/scott/workspace/mbel-work/tei2html/build/web teiFile=A10011
docName=A10011.xml
[echo] [tei-doc-to-html] Building html documents production=yes
[java] NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[echo] [tei-to-html] Build index.html, searchsite.html and solrsearch.html files 
[java] NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[java] NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[java] NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED

Why is this showing up in my custom log file?

Here is the code to create the logger and the call to log the message, the "Picked up..." is not in the message.

// create the new logger
    builder.add(builder.newLogger("BuildLogger", Level.OFF)
            .add(builder.newAppenderRef("rolling"))
            .addAttribute("additivity", false));

    /*builder.add(builder.newRootLogger(Level.DEBUG)
            .add(builder.newAppenderRef("rolling")));
    */
    ctx = Configurator.initialize(builder.build());
    LOGGER = LogManager.getLogger("BuildLogger");
    setup = true;
    //System.out.println("BuildLog.init: exit");
}

public static void userLog(String message) {
    if (setup == false) {
        init();
    }
    LOGGER.info(message);
}

Any way I can suppress this?

I did notice the Tomcat is setting these in the run script

# Add the JAVA 9 specific start-up parameters required by Tomcat
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.lang=ALL-UNNAMED"
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.base/java.io=ALL-UNNAMED"
JDK_JAVA_OPTIONS="$JDK_JAVA_OPTIONS --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED"
export JDK_JAVA_OPTIONS

I'm sure its no coincidence that these are the same options now showing up in my log file. Though it didn't happen until I upgraded Java.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ScottD
  • 23
  • 7
  • Because you upgraded Java. They are *required* in versions of Java >9 to work with the module system. Java has changed significantly over the years. Why would you expect it to be constant? – Elliott Frisch May 17 '23 at 23:36
  • Where is the `userLog()` method used? Am I wrong assumint that you: 1. use `ProcessBuilder` or similar to spawn a new JVM, 2. Call `userLog()` on each line that the new JVM outputs? BTW: `Configurator.initialize` does not replace the Log4j config if one already exists (i.e. you called a `LogManager` static method), use `Configurator.reconfigure` in this case. – Piotr P. Karwasz May 19 '23 at 17:28

1 Answers1

0

I moved the logging function down into the Ant script that was being called.

No problem now.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ScottD
  • 23
  • 7