arunkumar sambu
arunkumar sambu

Reputation: 663

How to turn off fakemongo logs

I am using Fongo, Fongo is an in-memory java implementation of MongoDB.

How to prevent these logs It creating a lengthy log which occupies a lot of space. I am using following dependencies

        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver</artifactId>
            <version>3.4.2</version>
        </dependency>
        <dependency>
            <groupId>com.github.fakemongo</groupId>
            <artifactId>fongo</artifactId>
            <version>2.1.1</version>
        </dependency>

I am getting this kind of logs

12:13:34.406 [TestNG-test=Package with subpackages-1] DEBUG com.mongodb.FongoDBCollection
12:13:34.406 [TestNG-test=Package with subpackages-1] DEBUG com.mongodb.FongoDBCollection
12:13:34.407 [TestNG-test=Package with subpackages-1] DEBUG com.mongodb.FongoDBCollection
12:13:34.407 [TestNG-test=Package with subpackages-1] DEBUG com.mongodb.FongoDBCollection
12:13:34.407 [TestNG-test=Package with subpackages-1] DEBUG com.github.fakemongo.impl.ExpressionParser 
12:13:34.407 [TestNG-test=Package with subpackages-1] DEBUG com.mongodb.FongoDBCollection

Getting huge logs for the following code (at line 3).

MongoCollection<Document> colls = db.getCollection("test_data");
Document criteriaDoc = (new Search(criteriaString)).getCriteria();
Document doc = colls.aggregate(Arrays.asList(Aggregates.match(criteriaDoc), Aggregates.sample(1))).first();

Upvotes: 2

Views: 306

Answers (1)

MyTwoCents
MyTwoCents

Reputation: 7622

I dont know what Log Implementaion you are using

Will try to generalise it.

You can set in log configuration what type of Log need to print in console and level as well like DEGUG, INFO, WARNING etc...

In Spring LogBack implementation logback.xml

<logger name="com.mongodb" level="WARNING"/>

Log4J properties file

props.setProperty("log4j.logger.org.mongodb.driver", "WARN");

You can also do it in Java

Logger mongoLogger = Logger.getLogger( "org.mongodb.driver" );
mongoLogger.setLevel(Level.WARNING); 

Upvotes: 0

Related Questions