Log only errors in MongoDB logs

11,685

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);
Share:
11,685

Related videos on Youtube

Ionică Bizău
Author by

Ionică Bizău

💻 Programmer ⚡️ Geek 🎹 Pianist & Organist 🚀 Learner 💡 Mentor 💫 Dreamer 🍏 Vegetarian 🙏 Jesus follower Website | GitHub | Twitter | PayPal Donations

Updated on June 04, 2022

Comments

  • Ionică Bizău
    Ionică Bizău almost 2 years

    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
    
  • Ionică Bizău
    Ionică Bizău over 9 years
    Still getting ... insert test.myCol ninserted:5000 messages. However, connection accepted messages are gone
  • Wizard
    Wizard over 9 years
    @Ionică Bizău, That's strange. I didn't get any message on the log while inserting. My version is 2.4.8, 2.6.4.
  • wdberkeley
    wdberkeley over 9 years
    The message about insert is logged because it is slow (> 100ms by default). You can change the behavior with setProfilingLevel.
  • Ionică Bizău
    Ionică Bizău over 9 years
    I don't want such messages to be logged. How can I solve this?
  • Ionică Bizău
    Ionică Bizău over 9 years
    @Wizard Tested is and it works! However, is there any way to ignore info logs? Example Thu Sep 25 18:25:40.945 [conn227] info DFM::findAll(): extent 0:3000 was empty, skipping ahead. ns:mono.sessions