Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change log level for MongoDB logs?

Is there any way to change the default log level for MongoDB ?

There're too many insertion/update entries in the log file, causing it grow way too big.

command used to start mongo:

./bin/mongod --fork --bind_ip 0.0.0.0 --dbpath /data/db/ --logpath /data/log/mongodb/mongod.log --logappend --quiet --logRotate reopen

the log file is filled with:

2018-08-31T11:30:46.831+0800 I COMMAND  [conn564] command eques.$cmd command: insert 

I just need error or more severe level entries.

like image 232
Jerry Chin Avatar asked Aug 31 '18 03:08

Jerry Chin


1 Answers

Check the verbosity levels first

db.getLogComponents()

Note : All components not specified explicitly in the configuration have a verbosity level of -1, indicating that they inherit the verbosity level of their parent, if they have one, or the global verbosity level (systemLog.verbosity) if they do not.

Use the db.setLogLevel(<level>, <component>) method to update a single component log level.

For a component, you can specify verbosity level of 0 to 5, or you can specify -1 to inherit the verbosity of the parent.

For example, the following sets the systemLog.component.query.verbosity to its parent verbosity (i.e. default verbosity):

db.setLogLevel(-1, "query")

More info : https://docs.mongodb.com/manual/reference/method/db.setLogLevel/

like image 81
Elshan Avatar answered Oct 25 '22 15:10

Elshan