Chapter 9.  Logging with Log4j2

All validation results will be reported using the logging system 'Log4j version 2'. This may seem unnecessarily complex, but it allowes the monitoring to be extended by other logging appenders. Other appenders may log to a file or to a log management system like Graylog2 and LogStash.

Current Configuration

The configuration file log4j2.xml is located in the directory PDFUNIT_MONITOR_HOME/conf.

Log4j2 is configured by PDFUnit to send log events not only to the appender 'PDFUnitMonitorAppender' but also to a file appender which writes to PDFUNIT_MONITOR_HOME/log/pdfunit-monitor.log.

<Configuration monitorInterval="10">

  <Appenders>
    <File name="XmlFileAppender" 
          fileName="./log/pdfunit-monitor.log" 
          append="true"
          bufferedIO="false"
          bufferSize="100"
          immediateFlush="true"
    >
      <XMLLayout complete="true" charset="UTF-8" compact="false"/>
    </File>
    <Console name="ConsoleAppender" target="SYSTEM_OUT">
      <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
    </Console>
    <Socket name="PDFUnitMonitorAppender" host="localHost" port="4445">
      <SerializedLayout />
    </Socket>
  </Appenders>
  
  <Loggers>
    <Logger name="PDFConstraints" level="all" additivity="false">
      <AppenderRef ref="XmlFileAppender"/>
      <AppenderRef ref="PDFUnitMonitorAppender"/>
<!--       <AppenderRef ref="ConsoleAppender"/> -->
    </Logger>
    <Root level="off">
      <AppenderRef ref="ConsoleAppender"/>
    </Root>
  </Loggers>
  
</Configuration>

Log-events can be filtered out by using a log level. By default, the level of the logger PDFConstraints is set to all. That means, all events will be sent to the result list. They can be filtered out from this list later by using the existing error-level filter.

Configure the Logging Port for Internal Use

The logging appender 'PDFUnitMonitorAppender' sends all validation events to the user interface using a socket. If its default port 4445 is beeing used by another application, change the port number in the files pdfunit-monitor.config and log4j2.xml.

Information about Log4j2

Further information about Log4j2 can be found in the Internet: