Deactivate logging in the Java-driver

3,144 views
Skip to first unread message

Ayman Nedjmeddine

unread,
Mar 14, 2015, 5:24:33 PM3/14/15
to mongod...@googlegroups.com
Hi,

The Java driver outputs some logging information when the connection to the database is established. I want that completely turn off.

Some replies on stackoverflow suggest that you can change the logging level by setting some System properties, then set the JUL to the wanted logging level.
What I did was this:

  System.setProperty("DEBUG.MONGO", "false");          
  System.setProperty("DB.TRACE", "false");             
  Logger.getLogger("com.mongodb").setLevel(Level.OFF); 

But that doesn't seem to have an effect.
So, how can I disable the logging output?

mongodb.version=3.0
mongodb.driver.version=3.0.0-beta3

Thanks!

Asya Kamsky

unread,
Mar 14, 2015, 5:26:08 PM3/14/15
to mongodb-user
Can you give an example of some of the logging output that you want to
suppress (the actual contents that are being printed out)?

Asya
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user"
> group.
>
> For other MongoDB technical support options, see:
> http://www.mongodb.org/about/support/.
> ---
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mongodb-user...@googlegroups.com.
> To post to this group, send email to mongod...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mongodb-user.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mongodb-user/b4bf2513-b50f-480d-8750-b80b29b3bae2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
MongoDB World is back! June 1-2 in NYC. Use code ASYA for 25% off!

Ayman Nedjmeddine

unread,
Mar 15, 2015, 8:34:08 PM3/15/15
to mongod...@googlegroups.com
Here's an example of it.  (screenshot attached)
Screenshot from 2015-03-16 01:28:10.png

Jeff Yemin

unread,
Mar 15, 2015, 8:38:35 PM3/15/15
to mongod...@googlegroups.com
Hi Ayman,

The 3.0.0 beta driver has switched to SLF4J for all logging.  The logging framework that you're using will dictate how you turn off logging.  See http://www.slf4j.org/manual.html#swapping to get started, and let me know if you need additional assistance.


Regards,
Jeff

Ian A. Mason

unread,
Apr 6, 2015, 11:19:00 AM4/6/15
to mongod...@googlegroups.com
Jeff,

What am I doing wrong?

My class path is: ".:./slf4j-nop-1.7.12.jar:./mongo-java-driver-3.0.0.jar"

I have a simple class that connects to my mongo db, but yet I still see:

Apr 06, 2015 8:03:33 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:1, serverValue:1236}] to iandev.sri.com:7777
Apr 06, 2015 8:03:33 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=iandev.sri.com:7777, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[2, 6, 9]}, minWireVersion=0, maxWireVersion=2, maxDocumentSize=16777216, roundTripTimeNanos=2544218}

I would really like to be able to turn of this.

Any advice?

Cheers, Ian.

Jeff Yemin

unread,
Apr 6, 2015, 12:16:36 PM4/6/15
to mongod...@googlegroups.com
I'm not sure Ian.

When I include the slf4j-nop artifact in my pom.xml I no longer see any output from the JULLogger or any other.  

Regards,
Jeff

Ian A. Mason

unread,
Apr 6, 2015, 12:55:42 PM4/6/15
to mongod...@googlegroups.com
So for those folks that don't want to use Maven or an IDE, just rely on javac and java, is there a way to programmatically
turn off the logging?

Jeff Yemin

unread,
Apr 6, 2015, 1:35:27 PM4/6/15
to mongod...@googlegroups.com
OK, I see the issue now.  Please try including slf4j-api-1.7.12.jar in your classpath, e.g

    java -classpath ".:./mongo-java-driver-3.0.0.jar:./slf4j-nop-1.7.12.jar:./slf4j-api-1.7.12.jar" Test

Otherwise the driver doesn't detect that SLF4J is present and falls back to JUL logging, so the no-op SLF4J logger is just being ignored.

I filed https://jira.mongodb.org/browse/JAVA-1746 to improve our docs for this.


Regards,
Jeff 

Ian A. Mason

unread,
Apr 6, 2015, 1:47:12 PM4/6/15
to mongod...@googlegroups.com
Ah silence! Thank you.

17369...@qq.com

unread,
Dec 8, 2015, 3:02:43 AM12/8/15
to mongodb-user


在 2015年3月15日星期日 UTC+8上午5:24:33,Ayman Nedjmeddine写道:
change the com.mongodb to org.mongodb.driver 
Reply all
Reply to author
Forward
0 new messages