Sha256: c3807dd921c65260e310e926b4403c3bba8bc8d56bc37669423d9c0a74b6cb42

Contents?: true

Size: 943 Bytes

Versions: 3

Compression:

Stored size: 943 Bytes

Contents

# 
# In development mode log also to STDOUT
# 
ActiveSupport::BufferedLogger.class_eval do
  def flush_with_stdout    
    STDOUT.write(buffer.join) if crystal.include?(:config) and crystal[:config].development? and !buffer.empty?
    flush_without_stdout
  end
  alias_method_chain :flush, :stdout
  
  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

3 entries across 3 versions & 2 rubygems

Version Path
crystal-0.0.13 lib/crystal/support/buffered_logger.rb
crystal-0.0.12 lib/crystal/support/buffered_logger.rb
crystal_ext-0.0.11 lib/crystal/support/buffered_logger.rb