ablog

不器用で落着きのない技術者のメモ

MariaDB Connector/J のロギング設定

As Per Lundberg already stated, logging is possible since version 1.5.0, see here.

To activate it, I added &log=true to my database URL. However, this was not sufficient. As explained here, the following steps are also needed:

First, we need to add some dependencies:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>[1.4.0,1.7.25]</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.2.3</version>
</dependency>
|xml|<
Then we need to configure logback like in the given example:
>|xml|
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="org.mariadb.jdbc" level="trace" additivity="false">
        <appender-ref ref="STDOUT"/>
    </logger>

    <root level="error">
        <appender-ref ref="STDOUT"/>
    </root>

</configuration>

The "trace" log level gives a lot of information, so you might want to use another one. The currently supported log levels are: trace, debug, info, warn or error

java - MariaDB JDBC Client Logging - Stack Overflow