1、加载log4j插件。通过maven管理 http://mvnrepository.com/artifact/log4j/log4j,增加一下配置项
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>
2、编辑配置文件 log4j.properties
# Direct log messages to stdout 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 # Root logger option log4j.rootLogger=INFO, stdout log4j.logger.org.hibernate.SQL=DEBUG log4j.logger.org.hibernate.type=ALL
具体项目可以参考官方说明 http://docs.jboss.org/hibernate/core/4.1/manual/en-US/html/ch03.html#configuration-logging
Table 3.9. Hibernate Log Categories