> For the complete documentation index, see [llms.txt](https://tech.x2bee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tech.x2bee.com/dev-guide/developer-guide-en/dev-start/integrations/logging-configuration.md).

# Logging Configuration

This document covers logging configuration.

Logging refers to writing the system so that it generates logs — a series of records that provide information.

Below, we explain the file structure for configuring query logging and how to configure the logback logging library.

***

## Logging-related Property Configuration

* Configure the logging file storage location
* Write the log4jdbc configuration
* Write the logback configuration
* Configure the logs printed to the system console

## Query Logging File Structure

Place the following files under the project's resource folder:

* src/main/resources/log4jdbc.log4j2.properties — Query logging log4jdbc configuration file
* src/main/resources/loback-spring.xml — logback-related configuration file

Example tree:

```
/src/main/resources
├─ log4jdbc.log4j2.properties
└─ loback-spring.xml
```

## Query Logging log4jdbc Configuration File (properties)

Add the following file under the resources folder.

Example file content:

```properties
log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator
log4jdbc.dump.sql.maxlinelength=0
```

## logback-related Configuration

* File location: create and configure the loback-spring.xml file under the src/main/resources/{ } folder
* consoleAppender: configure the log information output to the system console

Below is the full example content of the loback-spring.xml file.

{% code title="loback-spring.xml" %}

```xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />

    <springProperty scope="context" name="myappName" source="spring.application.name"/>

    <property name="MSG_FORMAT"
              value="%d{yyyy-MM-dd HH:mm:ss} [${myappName}] [%-5p] [%t] [%X{traceId},%X{spanId}] [%F::%M\(%L\)] [%X{requestURL}] : %m%n"/>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>${MSG_FORMAT}</pattern>
        </layout>
    </appender>

    <property name="COLOR_MSG_FORMAT"
              value="%clr(%d{yyyy-MM-dd HH:mm:ss}){faint} %clr([%-5p]) [%X{requestURL}] %clr([%X{traceId},%X{spanId}]){magenta} %clr([%30.-30F::%-20.20M\(%4L\)]){cyan} %clr(:){faint} %m%n"/>

    <appender name="COLOR_STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>${COLOR_MSG_FORMAT}</pattern>
        </layout>
    </appender>

    <springProfile name="local, default">
        <!-- log4jdbc 옵션 설정 -->
        <logger name="jdbc" level="OFF"/>
        <!-- 커넥션 open close 이벤트 로그로 남김 -->
        <logger name="jdbc.connection" level="OFF"/>
        <!-- SQL문만을 로그로 남기며, PreparedStatement일 경우 관련된 argument 값으로 대체된 SQL문이 보여짐 -->
        <logger name="jdbc.sqlonly" level="OFF"/>
        <!-- SQL문과 해당 SQL을 실행시키는데 수행된 시간 정보(milliseconds)를 포함 -->
        <logger name="jdbc.sqltiming" level="DEBUG"/>
        <!-- ResultSet을 제외한 모든 JDBC 호출 정보를 로그로 남김. 방대한 양의 로그 생성 -->
        <logger name="jdbc.audit" level="OFF"/>
        <!-- ResultSet을 포함한 모든 JDBC 호출 정보를 로그로 남김 -->
        <logger name="jdbc.resultset" level="OFF"/>
        <!-- SQL 결과 조회된 데이터의 table을 로그로 남김 -->
        <logger name="jdbc.resultsettable" level="DEBUG"/>

        <logger name="com.amazonaws" level="error"/>

        <logger name="org.springframework.jdbc.datasource.DataSourceTransactionManager" additivity="false" level="off">
            <appender-ref ref="COLOR_STDOUT" />
        </logger>

        <logger name="com.x2bee.common" additivity="false" level="debug">
            <appender-ref ref="COLOR_STDOUT" />
        </logger>

        <logger name="com.x2bee.api" additivity="false" level="debug">
            <appender-ref ref="COLOR_STDOUT" />
        </logger>

        <root level="info">
            <appender-ref ref="COLOR_STDOUT" />
        </root>
    </springProfile>

    <springProfile name="dev, stg, qa, prd">
        <appender name="logbackTcp" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
            <destination>fluentd-svc.thm-mgmt:24220</destination>
            <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                <providers>
                    <timestamp/>
                    <mdc />
                    <pattern>
                        <pattern> { "project": "${myappName}" } </pattern>
                    </pattern>
                    <logLevel/>
                    <context />
                    <threadName/>
                    <loggerName/>
                    <callerData/>
                    <message/>
                    <stackTrace/>
                </providers>
            </encoder>
        </appender>
    </springProfile>

    <springProfile name="dev, stg, qa">
        <logger name="com.x2bee.common" additivity="false" level="debug">
            <appender-ref ref="logbackTcp" />
        </logger>

        <logger name="com.x2bee.api" additivity="false" level="debug">
            <appender-ref ref="logbackTcp" />
        </logger>

        <root level="info">
            <appender-ref ref="logbackTcp" />
        </root>
    </springProfile>

    <springProfile name="prd">
        <logger name="com.x2bee.common" additivity="false" level="warn">
            <appender-ref ref="logbackTcp" />
        </logger>

        <logger name="com.x2bee.api" additivity="false" level="warn">
            <appender-ref ref="logbackTcp" />
        </logger>

        <root level="info">
            <appender-ref ref="logbackTcp" />
        </root>
    </springProfile>
</configuration>
```

{% endcode %}
