在MongoDB日志中仅记录错误 [英] Log only errors in MongoDB logs
问题描述
是否有仅将错误记录在MongoDB日志文件中的选项?
Is there any options for only logging the errors in MongoDB log files?
使用当前配置,似乎对Mongo服务器的每个请求都记录在日志文件中:
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
...
当前配置为:
# mongodb.conf
dbpath=/var/lib/mongodb
logpath=/var/log/mongodb/mongodb.log
logappend=true
如何将配置更新为仅记录错误?
How can be the configuration updated to only log errors?
正在运行Mongo shell version: 2.4.10
:
$ mongo --version
MongoDB shell version: 2.4.10
推荐答案
Appending quiet=true
will reduce a lot of output.
除了当前阶段的错误外,可能无法避免任何输出信息.
在配置文件中附加slowms=threshold
可以进一步减少常规日志输出.
threshold
是整数值(毫秒).这意味着如果一个操作持续时间不超过该值,则不会输出正常的日志信息.默认值为100.
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);
这篇关于在MongoDB日志中仅记录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!