Just a second...

Logging in Java

The Java™ client uses SLF4J to log messages. Provide a bindings library to implement the SLF4J API and log out the messages.

Log levels

Events are logged at different levels of severity. The log levels, ordered from most severe to least severe, are as follows:

Table 1. Log levels
Level Description
ERROR Events that indicate a failure.
WARN Events that indicate a problem with operation.
INFO Significant events.
DEBUG Verbose logging. Not usually enabled for production.
TRACE High-volume logging of interest only to DiffusionData Support. DiffusionData Support may occasionally ask you to enable this log level to diagnose issues.

Configuring logging in the Java client

The Java JAR, diffusion-client-x.x.x.jar, uses the SLF4J API to log messages. It does not include an implementation that outputs the log messages.

Many SLF4J implementations are available.
  1. Choose your preferred SLF4J implementation.
  2. Ensure that the bindings JAR is on the classpath of your Java client.
  3. Configure the SLF4J implementation to provide the logging behavior you require.

Log4j2

Log4j2 is a third-party SLF4J implementation provided by the Apache Software Foundation. For more information, see http://logging.apache.org/log4j/2.x/.

You can configure your Java clients to use log4j2 by completing the following steps:
  1. Get the log4j2 bindings libraries.

    The JAR files can be downloaded from https://logging.apache.org/log4j/2.0/download.html.

    The log4j2 JAR files are also located in the lib/thirdparty directory of the Diffusion™ installation.

  2. Ensure that the log4j-api.jar and log4j-core.jar files are on the client classpath.
  3. Create a configuration file and ensure that is present on the client classpath.
    The following example log4j2.xml file outputs the log messages to a rolling set of files:
    <Configuration status="warn" name="
                        
                        Diffusion
                    
                        
                    Client">
    
        <Properties>
            <Property name="my.log.dir">../logs</Property>
    
            <!-- The log directory can be be overridden using the system property 'my.log.dir'. -->
            <Property name="log.dir">${sd:my.log.dir}</Property>
    
            <Property name="pattern">%date{yyyy-MM-dd HH:mm:ss.SSS}|%level|%thread|%marker|%replace{%msg}{\|}{¦}|%logger%n%xEx
            </Property>
        </Properties>
    
        <Appenders> 
        
            <RollingRandomAccessFile name="file" immediateFlush="false" fileName="${log.dir}/client.log"
                filePattern="${log.dir}/$${date:yyyy-MM}/client-%d{MM-dd-yyyy}-%i.log.gz">
    
                <PatternLayout pattern="${pattern}" />
    
                <Policies>
                    <OnStartupTriggeringPolicy />
                    <TimeBasedTriggeringPolicy />
                    <SizeBasedTriggeringPolicy size="250 MB" />
                </Policies>
    
                <DefaultRolloverStrategy max="20" />
            </RollingRandomAccessFile>
        </Appenders>
    
        <Loggers>
            <AsyncRoot level="info" includeLocation="false">
                <AppenderRef ref="file" />
            </AsyncRoot>
        </Loggers>
    </Configuration>

    For more information about configuring log4j2, see https://logging.apache.org/log4j/2.0/manual/configuration.html.