How to rotate, override, or turn off logging from Sunspot Solr Rubygem?

折月煮酒 提交于 2019-12-20 14:32:33

问题


I've had great experiences with Sunspot Solr search for Ruby on Rails, however, its log files are growing incredibly large and I can't seem to find a way to either rotate, override, or turn off these logs (other than with very hacky methods that I'd rather not pursue).

I have a file, sunspot.yml in config/, where I tried setting the log_level flags to SEVERE, however, this had no effect.

I tried using the standard Logger.config rotation methods, however, that just sent my development log output to newly created files.

I would greatly appreciate any suggestions you can offer.


回答1:


It's a bit late, but looks like this is now handled inside config/sunspot.yml:

production:
  solr:
    hostname: thorn
    port: 8983
    log_level: WARNING
    min_memory: 512M
    max_memory: 1G
    solr_home: /u/solr



回答2:


In the console, this turns off all logging for me:

Sunspot::Rails::LogSubscriber.logger.level = 4
ActiveRecord::Base.logger.level = 4
Rails.logger.level = 4

My Gem versions:

  • sunspot (2.0.0.pre.130115)
  • sunspot_rails (2.0.0.pre.130115)
  • sunspot_solr (2.0.0.pre.130115)



回答3:


You're looking for the Solr logging.properties file to customize the Java container's logging behavior. Sunspot uses Jetty for its embedded Solr instance. The Solr wiki provides instructions for customizing logging.properties in Jetty at http://wiki.apache.org/solr/LoggingInDefaultJettySetup.

You may need to review the source code for Sunspot's rake tasks to determine the best place to inject your own logging.properties. I imagine this would be an interesting question to raise on the Sunspot mailing list for a potential patch to Sunspot.




回答4:


Currently the log_level is not handled correctly. The fix is on Github, which is a 2.x release.

You can wait for the next gem release. And if you don't and is not afraid of risk, you can use the following in the Gemfile:

# use selectively
gem 'sunspot_rails', :git => "git://github.com/sunspot/sunspot.git", :require =>  "sunspot_rails"
gem 'sunspot_solr', :git => "git://github.com/sunspot/sunspot.git", :require => "sunspot_solr"

I use Linux logrotate:

/home/path/log/*.log {
  su username pwd
  daily
  missingok
  rotate 7
  delaycompress
  notifempty
  copytruncate
}



回答5:


I've monkey patched the appropriate file in sunspot_solr to resolve this exact issue.

This code is not robust enough to survive rearchitecting/refactoring done directly in the sunspot_solr gem, so I recommend locking your sunspot_solr gem version to 1.3.0 for this to succeed.

You can drop the following into your project. We use it in a Rails project and have placed it at lib/sunspot/solr/server.rb:

module Sunspot
  module Solr
    class Server #:nodoc:

      def logging_config_path
        puts "# ==> Using monkey-patched Sunspot::Solr::Server#logging_config_path method"

        return @logging_config_path if defined?(@logging_config_path)
        @logging_config_path =
        if log_file
            logging_config = Tempfile.new('logging.properties')
            logging_config.puts("handlers = java.util.logging.FileHandler")
            logging_config.puts("java.util.logging.FileHandler.level = #{log_level.to_s.upcase}")
            logging_config.puts("java.util.logging.FileHandler.pattern = #{log_file}")
            logging_config.puts("java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter")

            # >>> ADDED THE FOLLOWING TWO LINES FOR JAVA-BASED LOG ROTATION <<<
            logging_config.puts("java.util.logging.FileHandler.count = 7")
            logging_config.puts("java.util.logging.FileHandler.limit = 104857600") # 100 megs

            logging_config.flush
            logging_config.close
            logging_config.path
          end
        end


      end # class Server
    end # module Solr
  end # module Sunspot


来源:https://stackoverflow.com/questions/4976175/how-to-rotate-override-or-turn-off-logging-from-sunspot-solr-rubygem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!