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:
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.
- Choose your preferred SLF4J implementation.
- Ensure that the bindings JAR is on the classpath of your Java client.
- 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/.
- 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.
- Ensure that the log4j-api.jar and log4j-core.jar files are on the client classpath.
- 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.