如何在控制台中禁用MongoDB日志消息? [英] How can I disable MongoDB log messages in console?
问题描述
我有这个小的测试脚本:
I have this little test script:
require 'mongo'
mongo_client = Mongo::Client.new(['127.0.0.1:27017'], :database => 'test')
mongo_client[:collection].insert_one({a: 1})
这是控制台输出:
$ ruby test.rb
D, [2015-05-17T21:12:05.504986 #25257] DEBUG -- : MONGODB | Adding 127.0.0.1:27017 to the cluster. | runtime: 0.0212ms
D, [2015-05-17T21:12:05.531238 #25257] DEBUG -- : MONGODB | COMMAND | namespace=admin.$cmd selector={:ismaster=>1} flags=[] limit=-1 skip=0 project=nil | runtime: 24.5481ms
D, [2015-05-17T21:12:05.554532 #25257] DEBUG -- : MONGODB | COMMAND | namespace=test.$cmd selector={:insert=>"collection", :documents=>[{:a=>1, :_id=><BSON::ObjectId:0x21935660 data=5558e80553657262a9000000>}], :writeConcern=>{:w=>1}, :ordered=>true} flags=[] limit=-1 skip=0 project=nil | runtime: 21.1718ms
我想禁用那些日志消息,我不想弄脏STDOUT.我没有在ruby驱动程序中找到任何选项,而且我也尝试使用这些指令编辑/etc/mongod.conf
(但它没有解决问题):
I want to disable those log messages, I don't want a dirty STDOUT. I didn't found any option for this in the ruby driver, and also I've tried to edit /etc/mongod.conf
with these directives (but it didn't fix it):
verbose = false
diaglog = 0
有什么主意吗?我不知道还能尝试什么!
Any idea? I don't know what else I can try!
推荐答案
此日志记录来自Ruby Mongo驱动程序.默认的日志记录级别似乎是Logger::DEBUG
.将其更改为更高的值以禁用调试输出:
This logging is coming from the Ruby Mongo driver. The default logging level seems to be Logger::DEBUG
. Change it to something higher to disable the debug output:
Mongo::Logger.logger.level = Logger::FATAL
要使驱动程序登录到日志文件,请执行以下操作:
To make the driver log to a logfile instead:
Mongo::Logger.logger = Logger.new('mongo.log')
Mongo::Logger.logger.level = Logger::INFO
请注意,如果您使用的是 Mongoid ODM ,那么您可能还需要在此处调整日志记录:
Note that if you're using the Mongoid ODM, then you may want to adjust logging there too:
Mongoid.logger = Logger.new('mongoid.log')
Mongoid.logger.level = Logger::INFO
对于 铁路与Mongoid 在application.rb
中:
config.mongoid.logger = Logger.new(Rails.root + '/log/mongoid.log', :warn)
# ...or change the logging level without a new file destination
config.mongoid.logger.level = Logger::INFO
这篇关于如何在控制台中禁用MongoDB日志消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!