How do you stop Java driver logging?

I’m using mongodb-driver-core-3.8.2 and want to stop logging from org.mongodb.driver.cluster. None of the 3 or 4 suggestions found on the Internet work. Most comments on the Internet suggest this: Logger.getLogger(“org.mongodb.driver”).setLevel(Level.SEVERE);
which doesn’t work for whatever reason.

In particular, I want to stop

Blockquote
2020-04-23 13:22:22.697 INFO 19154 — [ngodb.net:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address:27017=cluster0-shard-00-01-ue9rr.mongodb.net, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 6]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=48192417, setName=‘Cluster0-shard-0’, canonicalAddress:27017=cluster0-shard-00-01-ue9rr.mongodb.net, hosts=[cluster0-shard-00-00-ue9rr.mongodb.net:27017, cluster0-shard-00-01-ue9rr.mongodb.net:27017, cluster0-shard-00-02-ue9rr.mongodb.net:27017], passives=, arbiters=, primary=‘cluster0-shard-00-02-ue9rr.mongodb.net:27017’, tagSet=TagSet{[Tag{name=‘region’, value=‘US_EAST_1’}, Tag{name=‘provider’, value=‘AWS’}, Tag{name=‘nodeType’, value=‘ELECTABLE’}]}, electionId=null, setVersion=3, lastWriteDate=Thu Apr 23 13:22:20 CDT 2020, lastUpdateTimeNanos=917683913678847}
Blockquote
which is sent to output every few seconds.

Try using the Logger's Level OFF; this is a special level that can be used to turn off logging. Usage: logger.setLevel(Level.OFF).

Finally found the solution…

logging.level.org.mongodb=warn
logging.level.org.springframework.boot.autoconfigure.mongo.embedded=warn

2 Likes

Unfortunately, that didn’t work either.

Work for me. Thank you…

To suppress MongoDB Java Driver logging, I tried this and works fine:

Logger logger = Logger.getLogger("org.mongodb.driver");
logger.setLevel(Level.SEVERE);

I used Level.SEVERE instead of OFF, so that the severe errors can be logged and noted, ignoring all the other informational and warning messages. Depending upon your need you can also use other levels like Level.WARN, for example.

I think it is not a good idea to turn off logging altogether - some level of logging needs to be retained to capture those errors and warnings.