<commit_before>.. _ServerBuilder: apidocs/index.html?com/linecorp/armeria/server/ServerBuilder.html
.. _`RequestLog`: apidocs/index.html?com/linecorp/armeria/common/logging/RequestLog.html

.. _server-access-log:

Writing an access log
=====================

Configuring logging framework
-----------------------------

To write an access log, you need to configure a logging framework first. The following configurations are
simple examples of ``logback.xml`` and ``log4j2.xml`` respectively.

logback
^^^^^^^

.. code-block:: xml

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
          <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
      </appender>

      <appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>access.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
          <!-- daily rollover -->
          <fileNamePattern>access.%d{yyyy-MM-dd}-%i.log</fileNamePattern>
          <!-- each file should be at most 1GB, keep 30 days worth of history, but at most 30GB -->
          <maxFileSize>1GB</maxFileSize>
          <maxHistory>30</maxHistory>
          <totalSizeCap>30GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
          <pattern>%msg%n</pattern>
        </encoder>
      </appender>

      <logger name="com.linecorp.armeria.logging.access" level="INFO" additivity="false">
        <appender-ref ref="ACCESS"/>
      </logger>

      <root level="DEBUG">
        <appender-ref ref="CONSOLE"/>
      </root>
    </configuration><commit_msg>Fix typo in `logback.xml` example (#1052)<commit_after>.. _ServerBuilder: apidocs/index.html?com/linecorp/armeria/server/ServerBuilder.html
.. _`RequestLog`: apidocs/index.html?com/linecorp/armeria/common/logging/RequestLog.html

.. _server-access-log:

Writing an access log
=====================

Configuring logging framework
-----------------------------

To write an access log, you need to configure a logging framework first. The following configurations are
simple examples of ``logback.xml`` and ``log4j2.xml`` respectively.

logback
^^^^^^^

.. code-block:: xml

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
          <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
      </appender>

      <appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>access.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
          <!-- daily rollover -->
          <fileNamePattern>access.%d{yyyy-MM-dd}-%i.log</fileNamePattern>
          <!-- each file should be at most 1GB, keep 30 days worth of history, but at most 30GB -->
          <maxFileSize>1GB</maxFileSize>
          <maxHistory>30</maxHistory>
          <totalSizeCap>30GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
          <pattern>%msg%n</pattern>
        </encoder>
      </appender>

      <logger name="com.linecorp.armeria.logging.access" level="INFO" additivity="false">
        <appender-ref ref="ACCESS"/>
      </logger>

      <root level="DEBUG">
        <appender-ref ref="CONSOLE"/>
      </root>
    </configuration>
{'fraction_non_alphanumeric': 0.17210511117528154, 'fraction_numerical': 0.012128212532486284, 'mean_word_length': 2.8276243093922653, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 2, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5699131', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1046, 'n_words': 208}