Skip to content

"server-log" RollingFile Appender

This appender manages server logs with automatic file rotation.

Configuration example:

xml
<RollingFile name="server-log" fileName="logs/server.log" filePattern="logs/server-%d{yyyy-MM-dd}.log">
    <ThresholdFilter level="INFO"/>
    <PatternLayout pattern="%d %-5p [%t][%c][%X{MDC_USER}][%X{MDC_REMOTE_IP}] - %m%n"/>
    <Policies>
        <SizeBasedTriggeringPolicy size="256MB"/>
    </Policies>
    <DefaultRolloverStrategy max="10"/>
</RollingFile>

Example Log :

text
2025-02-06 15:17:26,487 INFO  [qtp398547146-82][com.okiok.sfiler.servlets.v2.SFilerDownloadQServlet][Business Partners\my-user][0:0:0:0:0:0:0:1] - Download completed: 06b29f6f-1c3e-4cc4-b891-061f065f5733

Log details:

  1. 2025-02-06 15:17:26,487 : Date and time of the log
  2. INFO : Log level
  3. [qtp398547146-82] : Thread name
  4. [com.okiok.sfiler.servlets.v2.SFilerDownloadQServlet] : Class name generating the log
  5. [Business Partners\my-user] : Username (from MDC)
  6. [0:0:0:0:0:0:0:1] : Remote IP address (from MDC)
  7. - Download completed: 06b29f6f-1c3e-4cc4-b891-061f065f5733 : Log message

Basic Configuration

  • Name: server-log
  • Output file: logs/server.log
  • Archive file pattern: logs/server-[DATE].log

Log Format

The pattern %d %-5p [%t][%c][%X{MDC_USER}][%X{MDC_REMOTE_IP}] - %m%n defines the following format:

  • %d : Log date and time
  • %-5p : Log level (DEBUG, INFO, ERROR...) aligned to 5 characters
  • [%t] : Thread name
  • [%c] : Class name generating the log
  • [%X{MDC_USER}] : Username (from MDC)
  • [%X{MDC_REMOTE_IP}] : Remote IP address (from MDC)
  • %m : Log message
  • %n : Line break

Rotation Policy

  • SizeBasedTriggeringPolicy: 256MB per file
  • DefaultRolloverStrategy: Maximum 10 archive files
  • Rotation creates a new file when:
    • Current file reaches 256MB
    • A new day begins (based on date pattern)

References