views:

83

answers:

3

As sad 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

A: 

You can try this:

Logger log = Logger.getLogger("org.hibernate");
        log.setLevel(Level.WARNING);

It should work. Just call it before you open any sessions.

npinti
thx, but this doesent work.
DartesMartes
He nice, this part helped me a lot to.. tnx .Well i used it to change the level in the source with out depending on the properites files.
DartesMartes
+1  A: 

Solution looks like adding slf4j-log4j12-1.5.2.jar in your classpath if you are using slf4j-api. This is other than configuration added for log4j for disabling logs.

This link should be useful.

http://ayushsuman.blogspot.com/2010/07/turning-off-hibernate-logging-console.html

You can also check other solutions from :

http://stackoverflow.com/questions/2077377/cant-stop-hibernate-from-writing-log-to-console-log4j-properties-is-ok

YoK
thx, this helps a lot, but this example generates multiple binding warnings of the loggers, but i am getting close to a solution. Tnx ull get a check >D
DartesMartes
so, the first link is not a solution, it just creates not configured ground. So, if u re using log4j binding, dont use slf4.simple.The solution is getting all the right versions.my solution was.Hibernate 3.5slf4j-api-1.6.1slf4j-log4j12-1.6.1log4j-1.2.16and setting the properties with the PropertyConfigurator from log4j, to FATAL
DartesMartes
@Yok @Martes I'm sorry but the blog post mentioned here is plain wrong (I left a comment to explain the problem but the author decided to ignore his mistake and deleted my comment). The author solved his problem "by accident" by putting several bindings on the classpath, hiding the `slf4j-simple` binding. But this is wrong and SLF4J will indeed complain about that. So no offense but this reference is just horribly wrong and this accepted answer is also incorrect. The solution is not to add random SLF4J bindings, the solution is to replace the `slf4j-simple` binding.
Pascal Thivent
A: 

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 to System.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.

Pascal Thivent
already solver, my comment explains it all. It was my dummy mestake, hibernate does not output if not sad u re right, and the problem was in my bindings, multiple bindings not a good idea, slf4-simple and log4j. but all is solved now. my upper comment shows my solution.And ill remember to give more info in future. Tnx
DartesMartes