Setting up logging

The Gateway Framework uses the Simple Logging Fa├žade for Java (SLF4J) to log messages. The framework supports Log4j2 version 2.22.1 as the default logging implementation, but you can configure the application to use other SLF4J implementations. Any logging implementation, such as Log4j or Logback, can be used on top of SLF4J.

Log4j2 logging configuration

The framework expects the log4j2.xml file to be available in the classpath. A sample configuration file is provided in the Gateway Framework artifacts bundle. Below is the content of the file:

Example 1. Sample log4j2.xml file
<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="warn"
               name="Gateway application"

        <Property name="log.dir">${sys:diffusion.home:-.}/logs</Property>

        <Property name="pattern">%date{yyyy-MM-dd HH:mm:ss.SSS}|%level|%thread|%replace{%msg}{\|}{}|%logger%n%xEx

        <Console name="console">
            <PatternLayout pattern="${pattern}"/>

        <RollingRandomAccessFile name="file" fileName="${log.dir}/gateway-application.log"

            <PatternLayout pattern="${pattern}"/>

                <SizeBasedTriggeringPolicy size="250 MB"/>

            <DefaultRolloverStrategy max="20"/>

        <Root level="info">
            <AppenderRef ref="console"/>
            <AppenderRef ref="file"/>
        <Logger name="com.pushtechnology.diffusion" level="info"/>

For more information about how to configure log4j2, see the log4j2 documentation. You can change the log4j2 logging behavior by editing the provided log4j2.xml configuration file.

When developing a Gateway application using an IDE, copy the log4j2.xml file into the 'src/main/resources' folder to ensure it is available in the classpath.