Class: Ougai::Formatters::Readable
- Defined in:
- lib/ougai/formatters/readable.rb
Overview
A human readble formatter with awesome_print
Instance Attribute Summary collapse
-
#excluded_fields ⇒ Array<String, Symbol>
The fields excluded from all logs.
-
#plain ⇒ Boolean
Whether log should be plain not colorized (by default this is off).
-
#trace_indent ⇒ Fixnum
The indent space size (by default this is 4).
Attributes inherited from Base
#app_name, #hostname, #trace_max_lines
Instance Method Summary collapse
- #call(severity, time, progname, data) ⇒ Object
- #colored_level(severity) ⇒ Object
- #create_err_str(data) ⇒ Object
-
#initialize(opts = {}) ⇒ Readable
constructor
A new instance of Readable.
Methods inherited from Base
#serialize_exc, #serialize_trace
Constructor Details
#initialize(opts = {}) ⇒ Readable
Returns a new instance of Readable.
12 13 14 15 16 17 18 |
# File 'lib/ougai/formatters/readable.rb', line 12 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 |
Instance Attribute Details
#excluded_fields ⇒ Array<String, Symbol>
The fields excluded from all logs.
9 10 11 |
# File 'lib/ougai/formatters/readable.rb', line 9 def excluded_fields @excluded_fields end |
#plain ⇒ Boolean
Whether log should be plain not colorized (by default this is off).
9 10 11 |
# File 'lib/ougai/formatters/readable.rb', line 9 def plain @plain end |
#trace_indent ⇒ Fixnum
The indent space size (by default this is 4).
9 10 11 |
# File 'lib/ougai/formatters/readable.rb', line 9 def trace_indent @trace_indent end |
Instance Method Details
#call(severity, time, progname, data) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ougai/formatters/readable.rb', line 20 def call(severity, time, progname, data) msg = data.delete(:msg) level = @plain ? severity : colored_level(severity) strs = ["[#{time.iso8601(3)}] #{level}: #{msg}"] 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 |
#colored_level(severity) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ougai/formatters/readable.rb', line 34 def colored_level(severity) case severity when 'TRACE' color = '0;34' when 'DEBUG' color = '0;37' when 'INFO' color = '0;36' when 'WARN' color = '0;33' when 'ERROR' color = '0;31' when 'FATAL' color = '0;35' else color = '0;32' end "\e[#{color}m#{severity}\e[0m" end |
#create_err_str(data) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/ougai/formatters/readable.rb', line 54 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 |