How can I disable MongoDB log messages in console?

前端 未结 2 1337
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 20:01

I have this little test script:

require \'mongo\'

mongo_client = Mongo::Client.new([\'127.0.0.1:27017\'], :database => \'test\')
mongo_client[:collection         


        
相关标签:
2条回答
  • 2020-12-23 20:05

    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
    

    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 
    

    For Rails + Mongoid in 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
    
    0 讨论(0)
  • 2020-12-23 20:31

    To disable the debug output for Ruby Mongo Driver(mongoid) we can add it specific environment file as

    config.mongoid.logger.level = Logger::INFO

    0 讨论(0)
提交回复
热议问题