0

Docx4j gives me a bunch of messages like this

[AWT-EventQueue-0] INFO org.docx4j.model.listnumbering.Emulator -

How to turn that off?

The following log configuration gets loaded, but doesnt turns the logging off.

    <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
    <param name="Target" value="System.out"/> 
    <layout class="org.apache.log4j.PatternLayout"> 
      <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/> 
    </layout> 
  </appender> 

  <root> 
    <priority value ="OFF" /> 
  </root>

</log4j:configuration>
user2147674
  • 2,319
  • 2
  • 14
  • 17

2 Answers2

1

I'm using docx4j 8.3.2, logged by slf4j 1.7.30 + logback 1.2.3. The annoying log messages disappeared after adding a logback.xml under src/main/resources. The logback.xml content:

<configuration>
    <appender name="STDOUT"
              class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
            by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} %line - %msg%n
            </pattern>
        </encoder>
    </appender>
    <!-- docx4j loggers -->
    <logger name="org.docx4j" level="ERROR" />
 
    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>
derek.z
  • 907
  • 11
  • 19
0

Add the following line to your configuration:

<logger name="org.docx4j.model.listnumbering.Emulator">
   <level value="ERROR" />
   <appender-ref ref="console"/>
</logger>

This will configure log4j to log only ERROR messages originating from logger org.docx4j.model.listnumbering.Emulator. If you want to turn off INFO messages from all classes/packages under org.docx4j, use the following:

<logger name="org.docx4j" >
    <level value="ERROR" />
    <appender-ref ref="console"/>       
</logger>

More information here : http://www.javabeat.net/baisc-steps-to-configure-log4j-using-xml-and-properties-file/

Priyesh
  • 2,041
  • 1
  • 17
  • 25
  • unfortunately I get an error if doing so: log4j:ERROR Parsing error on line 11 and column 42 log4j:ERROR Element type "Logger" must be declared. log4j:ERROR Parsing error on line 14 and column 23 log4j:ERROR The content of element type "log4j:configuration" must match "(renderer*,appender*,(category|logger)*,root?,categoryFactory?)". – user2147674 Jul 29 '15 at 10:49
  • Even after adding your code, I still get INFO logs from listnumbering – user2147674 Jul 29 '15 at 11:54
  • Can you share the code that sets up log4j? Is there a log4j.properties file in the classpath? – Priyesh Jul 29 '15 at 12:15
  • I dont set log4j up per code, I use a command line argument, which provides the log4j.properties – user2147674 Jul 30 '15 at 10:58
  • If a log4j.properties file is used, you cannot configure it using XML. You will have to add `log4j.org.docx4j=ERROR, console` in the log4j.properties file. – Priyesh Jul 30 '15 at 14:08