Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 392
Ionică Bizău Avatar asked Sep 18 '14 08:09

Ionică Bizău


People also ask

How do I log errors in MongoDB?

Let's take a look at the latest format for MongoDB errors which you can find by looking at your MongoDB log file which is commonly located at /var/log/mongodb/mongodb. log . If the file's not there, you'll need to find your mongodb. conf file which specifies where your log file lives.

How do I view MongoDB logs?

MongoDB logs can be found in the MongoDB log files at /var/log/mongodb/mongodb. log. If you can't find the log files from this location, you can check the mongodb. conf.

What is logs in MongoDB?

As part of normal operation, MongoDB maintains a running log of events, including entries such as incoming connections, commands run, and issues encountered. Generally, log messages are useful for diagnosing issues, monitoring your deployment, and tuning performance.

Is MongoDB good for logging?

We're all quite used to having log files on lots of servers, in disparate places.


1 Answers

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);
like image 105
Wizard Avatar answered Sep 23 '22 12:09

Wizard