Log4j2 Configuration

Configuration

The default Log4j2 configuration writes log output to 3 files:

Log file Description
app.log The main application log with information about the startup/shutdown process and with information about errors.
transactions.log The transactions log containing 3-D Secure protocol messages, except preparation messages, exchanged with the Directory Server and the ACS.
preq-pres.log The preparation request/response log containing the 3-D Secure protocol preparation messages exchanged with the Directory Server.

The log output is formatted according to a conversion pattern defined using a PatternLayout (file name: log4j2-prod.xml):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="60" schema="Log4J-config.xsd">
  <Properties>
    <Property name="log-path">logs</Property>
  </Properties>
  <Appenders>
    <RollingFile name="App-Appender" fileName="${log-path}/app.log" filePattern="${log-path}/app-%d{yyyy-MM-dd}.log">
      <PatternLayout>
        <pattern>
          [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%X{transaction.id}] %c{1} - %msg%n
        </pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy />
      </Policies>
    </RollingFile>
    <RollingFile name="Preparation-Request-Appender" fileName="${log-path}/preq-pres.log"
                 filePattern="${log-path}/preq-pres-%d{yyyy-MM-dd}.log">
      <PatternLayout>
        <pattern>
          [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%X{transaction.id}] %c{1} - %msg%n
        </pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy />
      </Policies>
    </RollingFile>
    <RollingFile name="Transaction-Message-Appender" fileName="${log-path}/transactions.log"
                 filePattern="${log-path}/transactions-%d{yyyy-MM-dd}.log">
      <PatternLayout>
        <pattern>
          [%-5level] %X{message.timestamp} [%t] [%X{transaction.id}] %c{1} - %msg%n
        </pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy />
      </Policies>
    </RollingFile>
  </Appenders>
 
  <Loggers>
    <Root level="info">
      <AppenderRef ref="App-Appender"/>
    </Root>
 
    <!-- define Preparation Request/Response logger -->
    <Logger additivity="false" name="com.netcetera.nca3dss.logger.file.PreparationRequestResponseLogger">
      <AppenderRef ref="Preparation-Request-Appender" />
    </Logger>
    <!--Logger for all other transactions-->
    <Logger additivity="false" name="com.netcetera.nca3dss.logger.file.TransactionMessageLogger">
      <AppenderRef ref="Transaction-Message-Appender" />
    </Logger>
 
  </Loggers>
</Configuration>

In addition to this, there are two more log4j2 configurations you can use. You can configure these using the logging.config property in the application properties.

Log output using a JSONLayout in the console (file name: log4j2-console-json.xml):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT" follow="true">
      <JSONLayout stacktraceAsString="true" compact="true" eventEol="true" properties="true"/>
    </Console>
  </Appenders>
 
  <Loggers>
    <Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
    <Logger name="org.apache.catalina.util.LifecycleBase" level="error" />
    <Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
    <Logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
    <Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
    <Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error" />
    <Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
    <Logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
    <Root level="info">
      <AppenderRef ref="Console" />
    </Root>
  </Loggers>
</Configuration>

Log output in the console regularly (file name: log4j2-console.xml):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Properties>
    <Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} %5p %pid --- [%t] [%X{organization.id}] [%X{protocol.type}] [%X{transaction.id}] %-40.40c{1.} : %m%n%xwEx</Property>
  </Properties>
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT" follow="true">
      <PatternLayout pattern="${sys:LOG_PATTERN}" />
    </Console>
  </Appenders>
  <Loggers>
    <Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
    <Logger name="org.apache.catalina.util.LifecycleBase" level="error" />
    <Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
    <Logger name="org.apache.sshd.common.util.SecurityUtils" level="warn"/>
    <Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
    <Logger name="org.eclipse.jetty.util.component.AbstractLifeCycle" level="error" />
    <Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
    <Logger name="org.springframework.boot.actuate.endpoint.jmx" level="warn"/>
    <Root level="info">
      <AppenderRef ref="Console" />
    </Root>
  </Loggers>
</Configuration>

Mapped Diagnostic Context (MDC)

The 3DS Server application uses Mapped Diagnostic Context (MDC) to expose additional information available for log output.

Exposed info is the 3DS Server Transaction ID.

You can use information exposed via MDC in your log output by using the following conversion pattern:

%X{transaction.id}

For more details about conversion patterns please refer to the Log4j PatternLayout documentation.

Use your own configuration

Although not recommended, you can use your own Log4j configuration.

To do so, you have to override the logging.config property in 3DS Server Configuration Properties which specifies the location of the log4j configuration.