As said in the title i want to stop Hibernate console output, without using log4j. I have tried to use log4j but i havent got anywhere. What i want is the console INFO outputs to stop. And if i am using log4j is it possible to do it without .properties or .xml files, just set the settings in the source. tnx
3 回答
你可以试试这个:
Logger log = Logger.getLogger("org.hibernate");
log.setLevel(Level.WARNING);
它应该工作。只需在打开任何会话之前调用它。
I can certify that Hibernate won't log on the console unless your configuration somehow allows it to do so. So, what version of Hibernate are you using? What SLF4J binding are you using if you're not using LOG4J as logging backend? Do you have a configuration file for it?
Or maybe did you turn on the echoing of SQL to stdout in your hibernate.cfg.xml
?:
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
You need to help readers a bit, we don't all have crystal balls :) Please provide more material.
Update: It appears that the OP had the slf4-simple
binding on his class path which is precisely used to output INFO
log messages to the console:
Binding for
Simple
implementation, which outputs all events toSystem.err
. Only messages of level INFO and higher are printed. This binding may be useful in the context of small applications.
Replacing slf4-simple
with another binding (you should not have multiple bindings on the class path) with the appropriate configuration should silence Hibernate.
如果您使用 slf4j-api,解决方案看起来像在类路径中添加 slf4j-log4j12-1.5.2.jar。这不是为 log4j 添加的用于禁用日志的配置。
这个链接应该很有用。
http://ayushsuman.blogspot.com/2010/07/turning-off-hibernate-logging-console.html
您还可以从以下位置查看其他解决方案: