MongoDB – How to Change Logging Level

loggingmongodb

We are experiencing huge logs creation in our MongoDB shard setup. Log settings used are default values –

            firstset:PRIMARY> db.getLogComponents()
  {
"verbosity" : 0,
"accessControl" : {
    "verbosity" : -1
},
"command" : {
    "verbosity" : -1
},
"control" : {
    "verbosity" : -1
},
"executor" : {
    "verbosity" : -1
},
"geo" : {
    "verbosity" : -1
},
"index" : {
    "verbosity" : -1
},
"network" : {
    "verbosity" : -1,
    "asio" : {
        "verbosity" : -1
    },
    "bridge" : {
        "verbosity" : -1
    }
},
"query" : {
    "verbosity" : -1
},
"replication" : {
    "verbosity" : -1
},
"sharding" : {
    "verbosity" : -1
},
"storage" : {
    "verbosity" : -1,
    "journal" : {
        "verbosity" : -1
    }
},
"write" : {
    "verbosity" : -1
},
"ftdc" : {
    "verbosity" : -1
}

}

We need only error and warning logs. Reference document (https://docs.mongodb.com/manual/reference/log-messages/) mentions these levels. I need to know how i can change the level.

Best Answer

You have the verbosity set to 0 overall and every individual component is set to -1, which means they will all inherit the parent verbosity setting (of 0). That is as low as the verbosity setting goes, to further reduce the logging you can set systemLog.quiet but that is not recommended for production systems because it can make tracking down issues too difficult and it may not address the root cause in any case.

You mention that the reason you are looking into this is the volume of logs you are seeing, so I would suggest the best thing to do would be to figure out what is causing the excessive logging (slow queries? something else?) at the lowest verbosity level and address that.

Note that if it is slow queries (and you are OK with them being that slow) you may just want to adjust the default 100ms operationProfiling.slowOpThresholdMs threshold upward to reduce that logging specifically.