Page 1 of 1

How to control docx4j logging?

PostPosted: Thu Apr 19, 2018 9:06 am
by dwilcoxen
In our web application we use the bind method, which generates a lot of messages to stderr. Since we don't want all that stuff in the production app server's system.err log, I'd like to turn it off. But, I haven't figured out how to control it.

The rest of the app uses log4j and my understanding is that slf4j should be using the underlying log4j configuration. Here's my log4j2.xml file:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
  <Properties>
    <Property name="outputLog">C:\temp\test.log</Property>
  </Properties>
  <Appenders>     
   <RollingFile name="Test_Appender" fileName="${outputLog}" filePattern="${outputLog}.%i" bufferedIO="false">
      <PatternLayout>
        <Pattern>%d [%T] [%p{length=1}]::%X::%c %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="2048 KB"/>
      </Policies>
      <DefaultRolloverStrategy max="20"/>
    </RollingFile>
  </Appenders>
  <Loggers>
    <Logger name="org.docx4j" level="error" additivity="false">
      <AppenderRef ref="Test_Appender"/>
    </Logger>
  </Loggers>
</Configuration>


The \temp\test.log file gets created so I know it's reading the XML config file, but nothing is written to it no matter what level I set the logger to. And regardless, I get many lines of output to stderr like:

Code: Select all
[main] INFO org.docx4j.jaxb.Context - java.vendor=Oracle Corporation
[main] INFO org.docx4j.jaxb.Context - java.version=1.8.0_151
[main] INFO org.docx4j.jaxb.NamespacePrefixMapperUtils - Using NamespacePrefixMapperSunInternal, which is suitable for Java 6
[main] INFO org.docx4j.jaxb.Context - Not using MOXy; using com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
[main] INFO org.docx4j.jaxb.Context - Using Java 6+ JAXB implementation
[main] WARN org.docx4j.utils.ResourceUtils - Couldn't get resource: docx4j.properties
[main] WARN org.docx4j.Docx4jProperties - Couldn't find/read docx4j.properties; docx4j.properties not found via classloader.
[main] INFO org.docx4j.XmlUtils - setProperty com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
[main] INFO org.docx4j.XmlUtils - actual: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
[main] INFO org.docx4j.XmlUtils - setProperty com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
[main] INFO org.docx4j.XmlUtils - actual: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
[main] INFO org.docx4j.openpackaging.contenttype.ContentTypeManager - Detected WordProcessingML package
[main] INFO org.docx4j.openpackaging.io3.Load3 - Instantiated package of type org.docx4j.openpackaging.packages.WordprocessingMLPackage
[main] INFO org.docx4j.utils.XPathFactoryUtil - xpath implementation: org.apache.xpath.jaxp.XPathFactoryImpl
...


And so on for hundreds of lines. I want to suppress that stuff.

Can you point me in the right direction? Thanks.

Re: How to control docx4j logging?

PostPosted: Thu Apr 19, 2018 4:29 pm
by jason
For comparison, here is docx4j's sample log4j config file: https://github.com/plutext/docx4j/blob/ ... /log4j.xml

Re: How to control docx4j logging?

PostPosted: Fri Apr 20, 2018 3:45 am
by dwilcoxen
Thanks for the reply, Jason. There appears to be some incompatibility with the way docx4j does logging and how the rest of our web application's logging is configured. Unfortunately, that's out of my control. I'm resigned to the messages going to stderr.

Re: How to control docx4j logging?

PostPosted: Fri Apr 20, 2018 2:06 pm
by jason
Don't give up yet, this should be easy to get right.

If docx4j is logging stuff, the logging configuration must be coming from somewhere ... what logging related files do you have on your classpath? Of especial interest is anything with slf4j in the jar filename.

You said your filename was log4j2.xml. Presumably that is a typo?

A long time ago, docx4j used to auto configure log4j, but i assume you are using a recent version: http://grepcode.com/file/repo1.maven.or ... rator.java

Re: How to control docx4j logging?

PostPosted: Tue Apr 24, 2018 3:55 am
by dwilcoxen
It really is log4j2.xml. https://logging.apache.org/log4j/2.x/manual/configuration.html

I don't know much about the latest updates to log4j but I assume the format has changed and the name indicates the format.

We do have the following two jars in the web app's classpath:

slf4j-api-1.7.12.jar
slf4j-simple-1.7.12.jar

also the log4j stuff:

log4j.jar
log4j-api-2.9.0.jar
log4j-core-2.9.0.jar
log4j-web.2.9.0.jar

Here are the full contents of our log4j2.xml file, which is located in the app's WEB-INF/classes directory:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
  <Properties>
    <Property name="outputLog">C:\Adjacent\Customer Projects\OAG\CVMS\Applications\Portal\Logging\Logs\WebPortal.output.log</Property>
   <Property name="shiroLog">C:\Adjacent\Customer Projects\OAG\CVMS\Applications\Portal\Logging\Logs\Shiro.log</Property>
  </Properties>
  <Appenders>
     <Console name="Console" target="SYSTEM_OUT">
     <PatternLayout>
        <Pattern>%d [%T] [%p{length=1}]::%X::%c %m%n</Pattern>
      </PatternLayout>
    </Console>
   <RollingFile name="WebPortal_Output_Appender" fileName="${outputLog}" filePattern="${outputLog}.%i" bufferedIO="false">
      <PatternLayout>
        <Pattern>%d [%T] [%p{length=1}]::%X::%c %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="2048 KB"/>
      </Policies>
      <DefaultRolloverStrategy max="20"/>
    </RollingFile>
   <RollingFile name="WebPortal_Shiro_Appender" fileName="${shiroLog}" filePattern="${shiroLog}.%i" bufferedIO="false">
      <PatternLayout>
        <Pattern>%d [%T] [%p{length=1}]::%X::%c %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="2048 KB"/>
      </Policies>
      <DefaultRolloverStrategy max="20"/>
    </RollingFile>
  </Appenders>
  <Loggers>
   <Logger name="org.apache.shiro" level="info" additivity="false">
     <AppenderRef ref="WebPortal_Shiro_Appender"/>
   </Logger>
    <Logger name="gov.oag.cvms" level="trace" additivity="false">
      <AppenderRef ref="WebPortal_Output_Appender"/>
    </Logger>
   <Logger name="com.adjacent.utilities" level="trace" additivity="false">
      <AppenderRef ref="WebPortal_Output_Appender"/>
    </Logger>
    <Logger name="org.docx4j" level="error" additivity="false">
      <AppenderRef ref="WebPortal_Output_Appender"/>
    </Logger>
  </Loggers>
</Configuration>


Thanks for taking a look.

Re: How to control docx4j logging?

PostPosted: Tue Apr 24, 2018 9:59 am
by jason
Try adding log4j-slf4j-impl-2.0.jar; see https://logging.apache.org/log4j/2.0/log4j-slf4j-impl/

And remove slf4j-simple-1.7.12.jar

Re: How to control docx4j logging?

PostPosted: Thu Oct 25, 2018 4:49 am
by dwilcoxen
And seven months later I return to see I never replied to your suggestion. Sorry. I was actually pulled into something else and didn't get to work on this until recently. Yes, the change in jars seems to have eliminated the system.err output or, rather, caused it to recognize my logging configuration settings. Thanks very much.