how to configure log4j logging for Ant FOP task?

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
Ron Van den Branden
Posts: 43

how to configure log4j logging for Ant FOP task?

Mon Sep 11, 2017 11:51 pm

Hi,

I have trouble getting logging right for an ANT transformation scenario that invokes a FOP task. Consider this simple Ant task:

Code: Select all

<target name="transform-pdf">
  <fop format="application/pdf"
          fofile="test.fo"
          outfile="test.pdf"
          messagelevel="debug"/>
</target>

...when I execute this with following jars on the classpath:

Code: Select all

${oxygenHome}/lib/fop.jar
${oxygenHome}/lib/batik-all-1.8.jar
${oxygenHome}/lib/commons-logging-1.2.jar
${oxygenHome}/lib/avalon-framework-api-4.3.1.jar
${oxygenHome}/lib/avalon-framework-impl-4.3.1.jar
${oxygenHome}/lib/commons-io-1.3.1.jar
${oxygenHome}/lib/xmlgraphics-commons-2.1.jar
${oxygenHome}/lib/log4j.jar

I'm getting following output for the Ant task in the transformation output pane:

Code: Select all

transform-pdf:
      [fop] log4j:WARN No appenders could be found for logger (org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry).
      [fop] log4j:WARN Please initialize the log4j system properly.

However, if I remove the ${oxygenHome}/lib/log4j.jar from the classpath, I am getting all regular FOP output in the transformation output pane.

Yet, I'm not sure if ${oxygenHome}/lib/log4j.jar is the recommended way of controlling logging in an Oxygen transformation scenario. If so, how should I configure log4j logging properly for ${oxygenHome}/lib/xmlgraphics-commons-2.1.jar (which is containing the org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry class)?

Best,

Ron
adrian
Posts: 2299

Re: how to configure log4j logging for Ant FOP task?

Tue Sep 12, 2017 4:09 pm

Hi,

However, if I remove the ${oxygenHome}/lib/log4j.jar from the classpath, I am getting all regular FOP output in the transformation output pane.
log4j also needs a configuration file, usually named log4j.properties. That's why you get that "log4j:WARN Please initialize the log4j system properly." message.

e.g. log4j.properties that logs everything on debug.

Code: Select all

log4j.rootCategory=DEBUG, R

# R is the standard output
log4j.appender.R=org.apache.log4j.ConsoleAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%r %p [ %t ] %c - %m%n

Normally just placing the log4j.properties file in the working directory, or the classpath folder works, but I found this is not the case with ANT.
So the easiest way I found for an ANT scenario is to keep the log4j.properties file in the same folder as the ant build file (or the file associated with the scenario), edit the ANT scenario and in the JVM Arguments specify this Java system property:

Code: Select all

-Dlog4j.configuration=${cfdu}/log4j.properties

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Ron Van den Branden
Posts: 43

Re: how to configure log4j logging for Ant FOP task?

Tue Sep 12, 2017 4:29 pm

Hi Adrian,

Thanks for your help.

Normally just placing the log4j.properties file in the working directory, or the classpath folder works, but I found this is not the case with ANT.
So the easiest way I found for an ANT scenario is to keep the log4j.properties file in the same folder as the ant build file (or the file associated with the scenario), edit the ANT scenario and in the JVM Arguments specify this Java system property:

Code: Select all

-Dlog4j.configuration=${cfdu}/log4j.properties



Unfortunately, this doesn't change the log output:

Code: Select all

[fop] log4j:WARN No appenders could be found for logger (org.apache.xmlgraphics.image.loader.spi.ImageImplRegistry).
[fop] log4j:WARN Please initialize the log4j system properly.

Could it be that the mentioned class is misconfigured somehow and in its current form incompatible with log4j?

Best,

Ron
adrian
Posts: 2299

Re: how to configure log4j logging for Ant FOP task?

Tue Sep 12, 2017 6:49 pm

Hi,
Unfortunately, this doesn't change the log output:
That means it's not seeing the log4j.configuration system property.
Check in the Java command line from transformation output log, you should find it after the -Xmx value.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Ron Van den Branden
Posts: 43

Re: how to configure log4j logging for Ant FOP task?

Wed Sep 13, 2017 10:43 am

Hi Adrian,

Ahh, I had put the -Dlog4j.configuration argument in the wrong place: "Additional arguments" instead of "JVM Arguments".

My bad, I can confirm it works perfectly if I accurately follow your earlier instructions and add the reference to the log4j properties file under "JVM Arguments".

Problem solved, many thanks!

Ron

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 0 guests