I have Spring MVC application integrated with Hibernate.
I'm trying to log jdbc SQL statement parameters using Log4j but it doesn't work. It seems like my log4j.properties configuration file does not make any changes. Here is project config:
I'm using Maven, Eclipse and log4j.properties file is at the top of the projects source folder (so as I understand in the classpath).
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TestProject</groupId>
<artifactId>TestProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<org.hibernate.version>3.6.0.Final</org.hibernate.version>
<org.springframework.version>3.1.2.RELEASE</org.springframework.version>
<org.apache.tiles.version>2.2.2</org.apache.tiles.version>
<slf4j-log4j12.version>1.7.0</slf4j-log4j12.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${org.hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.16.1-GA</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>${org.apache.tiles.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-log4j12.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-log4j12.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j-log4j12.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>
log4j.properties
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{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=ERROR, stdout
log4j.logger.main.mvc.model.hibernate=DEBUG
log4j.logger.org.hibernate=INFO
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
You are using this in your log4j config
Whereas it should be
OK. So I finally got it working!
All these troubles were caused by JBoss AS 7.1.
So here is how to set up slf4j+log4j logging on Spring MVC application that is run on JBoss AS 7.1:
These files gave me control over logs and I achieved my goal - logging Hibernate SQL statement parameters.
jboss-deployment-structure.xml
pom.xml
log4j.properties
Try with the following in your
hibernate.cfg.xml
or in yourpersistence.xml
:Plus the following inside your
log4j.properties
:I have no doubt you will have logs if you put these two files in the classpath of your webapp.
With Maven, you should put these files inside the folder
src/main/resources
. They will be packaged inside the resultingtarget
folder you will get if you do a 'mvn clean package`.To declare a slf4j logger, you should do this way:
And to limit a log level for a specific appender, you should use:
Note you are currently using:
Good luck!