如何重定向hibernate日志到文件
正在做的项目使用了hibernate,但hibernate的SQL一直只输出到console,并没有写到日志文件
项目使用的是log4j,调了log4j.properties也不起效,后来在hibernate官网发现一条说明:HibernateutilizesSimpleLoggingFacadeforJava(SLF4J)inordertologvarioussystemevents.
这才恍然大悟,原来我们的webserver启动起来一直报
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation
没有去理会,原来hibernate是用slf4j来做日志的facade,加上slf4j的依赖包后重启server就搞定了。
build.gradle的配置:
slf4j = ["org.slf4j:slf4j-log4j12:1.6.1"] compile = <jar...>,slf4j
log4j.properties的配置:
log4j.logger.org.hibernate.SQL=DEBUG,3rdPartyAppender log4j.additivity.org.hibernate=false
重启之后提示,hibernate.SQL日志能正常显示
SLF4J: Found binding in [jar:file:/C:/Users/maxeric/.gradle/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
参考:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html
相关推荐
CXC0 2020-06-14
chw0 2020-11-04
大唐帝国前营 2020-08-18
sdaq 2020-07-26
MrLiar 2020-07-07
sdaq 2020-06-16
丨Fanny丨Cri 2020-06-13
CXC0 2020-06-08
dongxurr 2020-06-07
sdaq 2020-06-06
MrLiar 2020-06-04
丨Fanny丨Cri 2020-06-03
MrLiar 2020-05-25
丨Fanny丨Cri 2020-05-17
MrLiar 2020-05-14
MrLiar 2020-05-12
sdaq 2020-05-11