Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # an application initializer which configures a rails application for logging
- #
- module RailsApp
- class Application < Rails::Application
- # load the libs - don't forget lockfile for process safe log rolling
- #
- require 'logging' unless defined?(Logging)
- require 'lockfile' unless defined?(Lockfile)
- # do the actual logging configuration - this one will keep 7 log files of
- # roughly 42 mega-bytes on disk and fill not your lovely drive - unless you
- # are in IRB, in which case the logger is not touched...
- #
- # it *seems* like this should be in an initializer but, alas, rails does
- # some weird things with dup'ing loggers that makes it safer to do right
- # *here*
- #
- unless STDIN.tty?
- require 'fileutils'
- FileUtils.mkdir_p(File.join(Rails.root, 'log'))
- logpath = config.paths.log.first.to_s
- number_rolled = 7
- megabytes = 2 ** 20
- max_size = 42 * megabytes
- options = { :safe => true } # for multi-process safe rolling with lockfile
- logger = ::Logging.logger(logpath, number_rolled, max_size, options)
- config.logger = logger
- config.logger.level = Rails.env.production? ? :info : :debug
- end
- end
- end
- ### you can test this using something like this
- #
- # rails runner 'p ActiveRecord::Base.logger; ActiveRecord::Base.logger.info("foobar"); ' < /dev/null
- # cat log/development.log
Add Comment
Please, Sign In to add comment