Sha256: 19d79625049fbbb89157b3a3104d8da525f9c2b44b7eaaedd0e9ec4791ba9751

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# 
# In development mode log also to STDOUT
# 
ActiveSupport::BufferedLogger.class_eval do
  
  def flush_with_stdout
    STDOUT.write(buffer.join) unless buffer.empty?
    flush_without_stdout
  end
  rad.after :config do
    if rad.include?(:config) and (rad.config.development? or rad.config.stdout_logger(false))      
      alias_method_chain :flush, :stdout
    end
  end
  
  
  def info_with_format obj
    info_without_format(obj_to_string(obj))
  end
  alias_method_chain :info, :format
  
  def warn_with_format obj
    warn_without_format("WARN: " + obj_to_string(obj))
  end
  alias_method_chain :warn, :format
  
  def error_with_format obj
    error_without_format("ERROR: " + obj_to_string(obj))
  end
  alias_method_chain :error, :format
  
  protected
    def obj_to_string obj
      if obj.is_a? Exception
        backtrace = (obj.backtrace && obj.backtrace.sfilter(Exception.common_filters)) || []
        %{\
#{obj.message}
  #{backtrace.join("\n  ")}
} 
      else
        obj.to_s
      end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 lib/rad/support/buffered_logger.rb