Reputation: 150
I'm using a Mongo Database to store information from my Java program. I'm using Eclipse and MongoDB 3.0 The problem I am having is that whenever my program has any interaction with Mongo it fills the console with red text from JULLogger.
I do not currently have any code to set the logger level, as all examples I have found on here or elsewhere online have given the error:
Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
mongoLogger.setLevel(Level.SEVERE);
"The method getLogger(String) is undefined for the type Logger"
Here is the output:
Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[127.0.0.1:27017],
mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: No server chosen by ReadPreferenceServerSelector{readPreference=primary} from cluster description
ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, all=[ServerDescription{address=127.0.0.1:27017,
type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:1, serverValue:117}] to 127.0.0.1:27017
Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description
ServerDescription{address=127.0.0.1:27017, type=STANDALONE,
state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 7]},
minWireVersion=0, maxWireVersion=3, electionId=null,
maxDocumentSize=16777216, roundTripTimeNanos=587005}
Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:2, serverValue:118}] to 127.0.0.1:27017
Document{{_id=567045259311932a6406b4e2, time=16:51:48, data=[31C, 38C, 20C]}}
Dec 16, 2015 8:49:58 AM com.mongodb.diagnostics.logging.JULLogger log
INFO: Closed connection [connectionId{localValue:2, serverValue:118}] to
127.0.0.1:27017 because the pool has been closed.
Could anyone advise me on how to remove all the Mongo logs from my console?
Upvotes: 2
Views: 5223
Reputation: 16
I tried all the above but none worked.the One which finally worked is
The one which finally worked for me is as below.
LoggerContext loggerContext = (LoggerContext)LoggerFactory.getILoggerFactory();
loggerContext.getLogger("org.mongodb.driver").setLevel(Level.ERROR);
Please note the imports as well:
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.LoggerFactory;
Upvotes: 0
Reputation: 1286
You can try this solution Just add following dependency in your pom file or add this jar manually
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.22</version>
</dependency>
Read these
for more and detailed explanation
I faced this similar kind of issue and it worked for me.
Upvotes: 1
Reputation: 150
Thank you very much Ross for your suggestion:
java.util.logging.Logger.getLogger("org.mongodb.driver").setLevel(java.util.logging.Level.SEVERE);
In fact the correct code was this, so only a minor change:
java.util.logging.Logger.getLogger("org.mongodb.driver").setLevel(Level.SEVERE);
I can confirm that I am not longer receiving any logs from mongo within the console at runtime.
Upvotes: 7