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})
An this is the console output:
这是控制台输出:
$ 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
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):
我要禁用那些日志消息,我不想要一个脏的STDOUT。我在ruby驱动程序中没有找到任何选项,我还尝试编辑/etc/mongod同意这些指示(但没有修正):
verbose = false
diaglog = 0
Any idea? I don't know what else I can try!
任何想法?我不知道还能尝试什么!
2 个解决方案
#1
87
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:
这个日志记录来自Ruby Mongo驱动程序。默认的日志记录级别似乎是::DEBUG。将其更改为更高级别以禁用调试输出:
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
Note that if you're using the Mongoid ODM, then you may want to adjust logging there too:
注意,如果您使用的是Mongoid ODM,那么您可能也需要调整日志记录:
Mongoid.logger = Logger.new('mongoid.log')
Mongoid.logger.level = Logger::INFO
For Rails + Mongoid in application.rb
:
用于Rails + Mongoid的应用。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
#2
1
To disable the debug output for Ruby Mongo Driver(mongoid) we can add it specific environment file as
要禁用Ruby Mongo驱动程序(mongoid)的调试输出,可以将其特定的环境文件添加为as
config.mongoid.logger.level = Logger::INFO
config.mongoid.logger。级别=记录器::信息
#1
87
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:
这个日志记录来自Ruby Mongo驱动程序。默认的日志记录级别似乎是::DEBUG。将其更改为更高级别以禁用调试输出:
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
Note that if you're using the Mongoid ODM, then you may want to adjust logging there too:
注意,如果您使用的是Mongoid ODM,那么您可能也需要调整日志记录:
Mongoid.logger = Logger.new('mongoid.log')
Mongoid.logger.level = Logger::INFO
For Rails + Mongoid in application.rb
:
用于Rails + Mongoid的应用。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
#2
1
To disable the debug output for Ruby Mongo Driver(mongoid) we can add it specific environment file as
要禁用Ruby Mongo驱动程序(mongoid)的调试输出,可以将其特定的环境文件添加为as
config.mongoid.logger.level = Logger::INFO
config.mongoid.logger。级别=记录器::信息