Skip to main content

Logging Configuration Reference

Overview

Datalogic JavaPOS API uses Apache Log4j2 to provide logging services. This document covers the default configuration of logging for Datalogic JavaPOS as well as a reference for some of the more common configuration changes. For a full reference to all available configuration options, please see the Apache Log4j2 Configuration Manual.

Reference

Character Set Encoding

Encoding is controlled by the first line of the configuration file. The encoding attribute accepts the name of whichever encoding is preferred for logging. Datalogic JavaPOS distributes with a default of windows-1252 encoding on the Microsoft Windows platform, and UTF-8 encoding on the Linux platform.

Example Encoding for Windows

<?xml version="1.0" encoding="windows-1252"?>

Example Encoding for Linux

<?xml version="1.0" encoding="utf-8"?>

Log Level

The threshold for logging messages can be adjusted in the Loggers element. Datalogic JavaPOS is distributed with a default Root element with the level attribute defaulted to debug. This denotes that all messages of level debug and lower are logged. The log level can be adjusted by changing the level attribute to one of the following levels:

  • trace - Entry and Exit to specific methods
  • debug - Debugging information
  • info - Informational Messages
  • warn - Warnings
  • error - Error Messages
  • fatal - Fatal Errors

Example Log Levels

<Root level="trace">
<Root level="debug">
<Root level="info">
<Root level="warn">
<Root level="error">
<Root level="fatal">

Log File Size

The maximum size of each rolling log file can be adjusted in the size attribute of the SizeBasedTriggeringPolicy element. Datalogic JavaPOS ships with a default setting of 20 MB for the size of each rolling log file. To set a custom size for each rolling log file, adjust the size attribute to the desired size.

Example Size adjustment

<SizeBasedTriggeringPolicy size="25 MB" />

Rollover Strategy

Rollover Size

The number of files to use when rolling over can be adjusted in the max attribute of the DefaultRolloverStrategy element. Datalogic JavaPOS ships with a default setting of 5 rolling log files. To set a custom number of rolling log files, adjust the max attribute to the desired number of rollover files.

Example Rollover max adjustment
<DefaultRolloverStrategy max="10" fileIndex="min"/>

Rollover Direction

The direction that files rollover can be adjusted in the fileIndex attribute of the DefaultRolloverStrategy element. Datalogic JavaPOS ships with a default setting of rolling to the minimum file. This means that the log file is rolled to name-1 and each log file is moved forward. To change direction, adjust the fileIndex attribute to the desired direction.

Default configuration file

Microsoft Windows Platform

<?xml version="1.0" encoding="windows-1252"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<RollingFile name="RollingFile" filename="${env:TEMP}/jposTraceR.log"
filePattern="${env:TEMP}/jposTraceR-%i.log">
<PatternLayout>
<pattern>%d{DEFAULT} [%t] %-5level %c{1} - %msg %throwable{short.localizedMessage}%n</pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
<DefaultRolloverStrategy max="5" fileIndex="min"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>