-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to log query string?
PostPosted: Wed Jan 28, 2015 2:43 am 
Newbie

Joined: Tue Jan 27, 2015 4:24 pm
Posts: 1
I'm using Hibernate OGM 4.1.0 with MongoDb. How to log query string to stdout? I configured the log setting as follow:
Code:
log4j.logger.org.hibernate=INFO, hb
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug

log4j.appender.hb=org.apache.log4j.ConsoleAppender
log4j.appender.hb.layout=org.apache.log4j.PatternLayout
log4j.appender.hb.layout.ConversionPattern=HibernateLog --> %d{HH:mm:ss} %-5p %c - %m%n
log4j.appender.hb.Threshold=TRACE

but I can't see any query string show in stdout.

When I do some query I get this:
Code:
HibernateLog --> 14:35:35 TRACE org.hibernate.type.CollectionType - Created collection wrapper: [com.filmore.domain.Film.comments#54c131d62377a16bc97fbef8]
HibernateLog --> 14:35:35 TRACE org.hibernate.type.CollectionType - Created collection wrapper: [com.filmore.domain.Film.comments#54c131d62377a16bc97fbef9]
HibernateLog --> 14:35:35 TRACE org.hibernate.type.CollectionType - Created collection wrapper: [com.filmore.domain.Film.comments#54c131f32377a16bc97fbefa]
HibernateLog --> 14:35:35 TRACE org.hibernate.type.CollectionType - Created collection wrapper: [com.filmore.domain.Film.comments#54c131f32377a16bc97fbefb]

I don't know what these messages mean.
Is there something wrong?
Thanks!


Top
 Profile  
 
 Post subject: Re: How to log query string?
PostPosted: Wed Jan 28, 2015 7:15 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

Nothing wrong here really, only it's not doable atm. to log the interactions with the MongoDB server :)

You can enable logging specifically for Hibernate OGM:

log4j.logger.org.hibernate.ogm=TRACE

(or e.g. log4j.logger.org.hibernate.ogm.datastore.mongodb=TRACE just for the MongoDB backend)

Amongst others this will show the interactions between the Hibernate OGM engine and the specific grid dialect, MongoDBDialect from hibernate-ogm-mongodb in this case. This gives you a general indication of what's going on, but it doesn't really show the interactions between the dialect and the actual datastore (e.g. the dialect may trigger only one aggregated backend invocation based on several dialect invocations).

Unfortunately the logging of datastore invocations cannot be done in a generic way, e.g. MongoDB doesn't work with query strings, so here we'd have to log API invocations. Whereas for Neo4j, we might log Cypher queries in some cases.

I've filed https://hibernate.atlassian.net/browse/OGM-728 to improve upon that. Should you like to give this a try and e.g. contribute proper logging for the MongoDB backend, I'd be thrilled! Just let us know and we'll get you started.

Btw. the "org.hibernate.SQL" category doesn't apply to Hibernate OGM as we don't execute any SQL.

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: How to log query string?
PostPosted: Wed Jan 28, 2015 8:18 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

On a second thought, what you actually can do is to enable logging within the MongoDB driver itself.

It uses the JDK Util logging, see this post on SO on how to enable it: https://stackoverflow.com/questions/9545341/configure-logging-for-the-mongodb-java-driver.

I quickly tried it (by adding the following few lines the begin of my program) and it shows all the issued ops nicely:

Code:
// Enable logging of all levels
Logger mongoLogger = Logger.getLogger( "com.mongodb" );
mongoLogger.setLevel(Level.ALL);

// Also show FINER and below on console
Handler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.ALL);
mongoLogger.addHandler( consoleHandler );


Of course it's not a general solution for logging backend interactions in Hibernate OGM, but it may do the trick for you for the time being.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.