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"
               shutdownHook="disable"
               monitorInterval="30">

    <Properties>
        <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
        </Property>
    </Properties>

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

        <RollingRandomAccessFile name="file" fileName="${log.dir}/gateway-application.log"
                                 filePattern="${log.dir}/$${date:yyyy-MM}/gateway-application-%d{MM-dd-yyyy}-%i.log.gz">

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

            <Policies>
                <OnStartupTriggeringPolicy/>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="250 MB"/>
            </Policies>

            <DefaultRolloverStrategy max="20"/>
        </RollingRandomAccessFile>
    </Appenders>

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

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.