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

2020-04-23 13:22:22.697 INFO 19154 — [] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{, 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’,, hosts=[,,], passives=, arbiters=, primary=‘’, 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}
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…

1 Like

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");

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.