I am learning Spring now and currently trying to configure slf4j with logback to log MySQL statements in test environment. As far as I understand I configured everything to get MySQL logs, but I do not see anything. Logging works for other loggers, except for Connector/J driver. What should I fix in my code? My configs are below:
pom.xml contains these dependencies:
<!-- Logging with SLF4J & LogBack -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>runtime</scope>
</dependency>
logback-test.xml
<configuration>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>%d{HH:mm:ss.SSS} %-5level %class{50}.%M:%L - %msg%n</pattern>
</encoder>
</appender>
<logger name="com.mysql" level="debug"/>
<logger name="org.springframework.jdbc" level="info"/>
<logger name="ru.javawebinar.topjava" level="debug"/>
<root level="INFO">
<appender-ref ref="console"/>
</root>
I am using Spring's JDBC template to access DB like that:
public List<Meal> getAll(int userId) {
return jdbcTemplate.query(
"SELECT * FROM meals WHERE user_id=? ORDER BY date_time DESC", ROW_MAPPER, userId);
}
and my connection string url is
jdbc:mysql://localhost:3306/topjava?logger=Slf4JLogger
Sorry for the dumb question, but I really stuck here.