Ionică Bizău
Ionică Bizău

Reputation: 113485

Log only errors in MongoDB logs

Is there any options for only logging the errors in MongoDB log files?

With the current configuration, it seems that every request to Mongo server is logged in log files:

Wed Sep 17 08:08:07.030 [conn117] insert my_database.myCol ninserted:1 keyUpdates:0 locks(micros) w:243505 285ms
Wed Sep 17 08:08:54.447 [conn101] command anotherDatabase.$cmd command: { findandmodify: "myCol", query: { ... }, new: 0, remove: 0, upsert: 0, fields: {...}, update: {...} } update: {...} ntoreturn:1 idhack:1 nupdated:1 fastmod:1 keyUpdates:0 locks(micros) w:124172 reslen:248 124ms
Wed Sep 17 08:10:24.370 [conn95] command my_database.$cmd command: { count: "cms.myCol", query: { ... }, fields: null } ntoreturn:1 keyUpdates:0 locks(micros) r:197368 reslen:48 197ms
...

The current configuration is:

# mongodb.conf

dbpath=/var/lib/mongodb
logpath=/var/log/mongodb/mongodb.log
logappend=true

How can be the configuration updated to only log errors?

Running Mongo shell version: 2.4.10:

$ mongo --version
MongoDB shell version: 2.4.10

Upvotes: 5

Views: 13358

Answers (1)

Wizard
Wizard

Reputation: 4431

Appending quiet=true will reduce a lot of output.


Perhaps it is impossible to avoid any output information except error on current stage.
Appending slowms=threshold to configuration file can reduce normal log output further.
threshold is a integer value (milliseconds). It means if one operation duration doesn't exceed this value, normal log information won't output. The default value is 100.

Also, you can change this value by another way if the instance is running.

var slowms = theValueYouWant; 
var level = db.getProfilingStatus().was;
db.setProfilingLevel(level, slowms);

Upvotes: 7

Related Questions