diff options
Diffstat (limited to 'activesupport/lib/active_support')
5 files changed, 27 insertions, 120 deletions
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index 775f9928e6..36e29644c6 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -1,125 +1,10 @@ require 'thread' -require 'logger' -require 'active_support/core_ext/logger' require 'active_support/core_ext/class/attribute_accessors' require 'active_support/deprecation' +require 'active_support/logger' require 'fileutils' module ActiveSupport - # Inspired by the buffered logger idea by Ezra - class BufferedLogger - module Severity - DEBUG = 0 - INFO = 1 - WARN = 2 - ERROR = 3 - FATAL = 4 - UNKNOWN = 5 - end - include Severity - - MAX_BUFFER_SIZE = 1000 - - ## - # :singleton-method: - # Set to false to disable the silencer - cattr_accessor :silencer - self.silencer = true - - # Silences the logger for the duration of the block. - def silence(temporary_level = ERROR) - if silencer - begin - logger = self.class.new @log_dest, temporary_level - yield logger - ensure - logger.close - end - else - yield self - end - end - deprecate :silence - - attr_reader :auto_flushing - deprecate :auto_flushing - - def initialize(log, level = DEBUG) - @level = level - @log_dest = log - - unless log.respond_to?(:write) - unless File.exist?(File.dirname(log)) - ActiveSupport::Deprecation.warn(<<-eowarn) -Automatic directory creation for '#{log}' is deprecated. Please make sure the directory for your log file exists before creating the logger. - eowarn - FileUtils.mkdir_p(File.dirname(log)) - end - end - - @log = open_logfile log - end - - 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 - deprecate :open_log - - def level - @log.level - end - - def level=(l) - @log.level = l - end - - def add(severity, message = nil, progname = nil, &block) - @log.add(severity, message, progname, &block) - end - - # Dynamically add methods such as: - # def info - # def warn - # def debug - Severity.constants.each do |severity| - class_eval <<-EOT, __FILE__, __LINE__ + 1 - def #{severity.downcase}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block) - add(#{severity}, message, progname, &block) # add(DEBUG, message, progname, &block) - end # end - - def #{severity.downcase}? # def debug? - #{severity} >= level # DEBUG >= @level - end # end - EOT - 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. - def auto_flushing=(period) - end - deprecate :auto_flushing= - - def flush - end - deprecate :flush - - def respond_to?(method, include_private = false) - return false if method.to_s == "flush" - super - end - - def close - @log.close - end - - private - def open_logfile(log) - Logger.new log - end - end + BufferedLogger = ActiveSupport::Deprecation::DeprecatedConstantProxy.new( + 'BufferedLogger', '::ActiveSupport::Logger') end diff --git a/activesupport/lib/active_support/core_ext.rb b/activesupport/lib/active_support/core_ext.rb index 46a8609dd7..b48bdf08e8 100644 --- a/activesupport/lib/active_support/core_ext.rb +++ b/activesupport/lib/active_support/core_ext.rb @@ -1,3 +1,4 @@ Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"].sort.each do |path| + next if File.basename(path, '.rb') == 'logger' require "active_support/core_ext/#{File.basename(path, '.rb')}" end diff --git a/activesupport/lib/active_support/core_ext/logger.rb b/activesupport/lib/active_support/core_ext/logger.rb index e63a0a9ed9..a51818d2b2 100644 --- a/activesupport/lib/active_support/core_ext/logger.rb +++ b/activesupport/lib/active_support/core_ext/logger.rb @@ -1,4 +1,7 @@ require 'active_support/core_ext/class/attribute_accessors' +require 'active_support/deprecation' + +ActiveSupport::Deprecation.warn 'this file is deprecated and will be removed' # Adds the 'around_level' method to Logger. class Logger #:nodoc: diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index dcfcf0b63c..7b7fc81e6c 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -50,7 +50,7 @@ module ActiveSupport end class MockLogger - include ActiveSupport::BufferedLogger::Severity + include ActiveSupport::Logger::Severity attr_reader :flush_count attr_accessor :level @@ -73,7 +73,7 @@ module ActiveSupport @flush_count += 1 end - ActiveSupport::BufferedLogger::Severity.constants.each do |severity| + ActiveSupport::Logger::Severity.constants.each do |severity| class_eval <<-EOT, __FILE__, __LINE__ + 1 def #{severity.downcase}? #{severity} >= @level diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb new file mode 100644 index 0000000000..66e8fcadb4 --- /dev/null +++ b/activesupport/lib/active_support/logger.rb @@ -0,0 +1,18 @@ +require 'logger' + +module ActiveSupport + class Logger < ::Logger + def initialize(*args) + super + @formatter = SimpleFormatter.new + end + + # Simple formatter which only displays the message. + class SimpleFormatter < ::Logger::Formatter + # This method is invoked when a log event occurs + def call(severity, timestamp, progname, msg) + "#{String === msg ? msg : msg.inspect}\n" + end + end + end +end |