0

I am working on spring (5.1.9. Release) JDBC project with log4j dependency and deployed the web application on Tomcat 8.5.

Below is a snippet of pom.xml file for my project:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.1.9.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.1.9.RELEASE</version>
</dependency>

Also, this is the log4j.properties file available in resource folder in my project:

# Root logger option
log4j.rootLogger=stdout,DEBUG

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm} %-5p %c{1}:%L - %m%n
log4j.appender.stdout.Threshold=DEBUG

log4j.category.org.springframework=TRACE

I just want to print the debug logs for my Spring JDBC but it seems to be not working.

I have gone through several solutions but it is not showing the debug logs of spring JDBC on console.

What am I missing in the above configuration?

halfer
  • 19,824
  • 17
  • 99
  • 186
Beast
  • 639
  • 2
  • 14
  • 29

1 Answers1

0

Following configuration should be added in your log4j.properties file:

log4j.logger.org.springframework.jdbc.core=DEBUG
log4j.logger.org.springframework.jdbc.core.StatementCreatorUtils=TRACE
Ihor Patsian
  • 1,288
  • 2
  • 15
  • 25
  • [~Igor Patsyan] I have tried the solution and added the above properties in log4j.properties. But I dont see the debug logs when I start my tomcat 8.5 in debug mode from eclipse. – Beast Sep 08 '19 at 08:45
  • Are you sure log4j is configured properly? Please see https://stackoverflow.com/a/1140498/3657460 – Ihor Patsian Sep 09 '19 at 09:07
  • [~Igor ] Aplogy for the latereply. I have configured tomcat in my eclipse sts.I have gone through your post providedin previous comment and added the argument (-Dlog4j.debug) in tomcat VM arguments. I dont see any debug information displayed in console as mentioned in post. I have already posted all my configuration related to project in my question. Am i missing something? – Beast Sep 10 '19 at 16:25
  • Do you see any log4j warnings in the console at the start of the application? – Ihor Patsian Sep 10 '19 at 20:54