lib/ougai/formatters/readable.rb in ougai-1.0.0 vs lib/ougai/formatters/readable.rb in ougai-1.1.0

- old
+ new

@@ -1,29 +1,28 @@ require 'ougai/formatters/base' module Ougai module Formatters class Readable < Base - attr_accessor :plain, :trace_indent + attr_accessor :plain, :trace_indent, :excluded_fields def initialize(opts = {}) super(opts[:app_name], opts[:hostname]) @trace_indent = opts[:trace_indent] || 4 @plain = opts[:plain] || false + @excluded_fields = opts[:excluded_fields] || [] load_awesome_print end def call(severity, time, progname, data) msg = data.delete(:msg) level = @plain ? severity : colored_level(severity) strs = ["[#{time.iso8601(3)}] #{level}: #{msg}"] - if data.key?(:err) - err = data.delete(:err) - err_str = " #{err[:name]} (#{err[:message]}):" - err_str += "\n " + err[:stack] if err.key?(:stack) + if err_str = create_err_str(data) strs.push(err_str) end + @excluded_fields.each { |f| data.delete(f) } unless data.empty? strs.push(data.ai({ plain: @plain })) end strs.join("\n") + "\n" end @@ -40,9 +39,17 @@ color = '0;35' else # DEBUG color = '0;37' end "\e[#{color}m#{severity}\e[0m" + end + + def create_err_str(data) + return nil unless data.key?(:err) + err = data.delete(:err) + err_str = " #{err[:name]} (#{err[:message]}):" + err_str += "\n " + err[:stack] if err.key?(:stack) + err_str end private def load_awesome_print