[JAVA-932] How to disable driver logging Created: 21/Aug/13  Updated: 11/Sep/19  Resolved: 23/Jun/15

Status: Closed
Project: Java Driver
Component/s: Error Handling
Affects Version/s: 2.11.2
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Alex Ryan Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The following code can be used to change the level at which events are logged by clients of the driver ...

import java.util.logging.Logger;
Logger mongoLogger = Logger.getLogger( "com.mongodb" );
mongoLogger.setLevel(Level.SEVERE);

However, rather than have to write this code in many different places, I'd really like to have the ability to set the logging level in a single place. For example, the Amazon SDK, hc.apache and others allow me to do this in a log4j.properties file like so:

  1. Uncomment to turn off all logging from the SDK
    log4j.logger.com.amazonaws=OFF
  1. More examples – adjust to see more / less logging
    #log4j.logger.com.amazonaws.ec2=WARN
    #log4j.logger.httpclient.wire=WARN

log4j.logger.org.apache.http=OFF
#log4j.logger.org.apache.http=DEBUG
#log4j.logger.org.apache.http.wire=ERROR
#log4j.logger.org.apache.http.impl.conn=ERROR
#log4j.logger.org.apache.http.impl.client=ERROR
#log4j.logger.org.apache.http.client=ERROR

Is there any way to do something like this with the mongoDB java driver?



 Comments   
Comment by Jeffrey Yemin [ 27/Mar/14 ]

In 3.0 the driver will log to SLF4J if it's present on the class path. SLF4J integrates better with log4j, and so I think will give you a better solution to this problem. As it is now, the driver uses JUL (java.util.logging), which has poor integration with log4j. Specifically, I don't think you can control the logging level for JUL via log4j properties

Comment by Jeffrey Yemin [ 04/Dec/13 ]

Are you saying that this?

log4j.logger.com.mongodb=SEVERE

has no effect? If so, we can investigate.

Generated at Thu Feb 08 08:53:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.