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 rot
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
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:
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
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.
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
}