Inspired by the buffered logger idea by Ezra
# File lib/active_support/buffered_logger.rb, line 47 def initialize(log, level = DEBUG) @log_dest = log unless log.respond_to?(:write) unless File.exist?(File.dirname(log)) ActiveSupport::Deprecation.warn("Automatic directory creation for '#{log}' is deprecated. Please make sure the directory for your log file exists before creating the logger. ") FileUtils.mkdir_p(File.dirname(log)) end end @log = open_logfile log self.level = level end
Set to false to disable the silencer
# File lib/active_support/buffered_logger.rb, line 26 cattr_accessor :silencer
# File lib/active_support/buffered_logger.rb, line 79 def add(severity, message = nil, progname = nil, &block) @log.add(severity, message, progname, &block) end
Set the auto-flush period. Set to true to flush after every log message, to an integer to flush every N messages, or to false, nil, or zero to never auto-flush. If you turn auto-flushing off, be sure to regularly flush the log yourself – it will eat up memory until you do.
# File lib/active_support/buffered_logger.rb, line 103 def auto_flushing=(period) end
# File lib/active_support/buffered_logger.rb, line 116 def close @log.close end
# File lib/active_support/buffered_logger.rb, line 107 def flush end
# File lib/active_support/buffered_logger.rb, line 71 def level @log.level end
# File lib/active_support/buffered_logger.rb, line 75 def level=(l) @log.level = l end
# File lib/active_support/buffered_logger.rb, line 63 def open_log(log, mode) open(log, mode).tap do |open_log| open_log.set_encoding(Encoding::BINARY) if open_log.respond_to?(:set_encoding) open_log.sync = true end end
# File lib/active_support/buffered_logger.rb, line 111 def respond_to?(method, include_private = false) return false if method.to_s == "flush" super end
Silences the logger for the duration of the block.
# File lib/active_support/buffered_logger.rb, line 30 def silence(temporary_level = ERROR) if silencer begin logger = self.class.new @log_dest.dup, temporary_level yield logger ensure logger.close end else yield self end end