How to log spring JdbcTemplate sql queries and DB response in log file using log4j2
I'd say name="org.springframework.jdbc.core.JdbcTemplate"
is very 'strict'. Try this category:
org.springframework.jdbc
<Logger name="org.springframework.jdbc.core.JdbcTemplate" level="TRACE" additivity="false"> <Appender-Ref ref="db" /></Logger>
This will definitely work. debug and trace both level will work. Only thing is JDBCTemplate is using common-logging API to log. And if you are using log4j in your application, you will have to add common logging bridge for the same.
Add following in your pom.xml
<dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-jcl</artifactId> <version>2.0-rc1</version> </dependency>