Class: Ougai::Formatters::Readable

Inherits:
Base
  • Object
show all
Defined in:
lib/ougai/formatters/readable.rb

Overview

A human readble formatter with amazing_print

Instance Attribute Summary collapse

Attributes inherited from Base

#app_name, #hostname, #serialize_backtrace, #trace_indent, #trace_max_lines

Instance Method Summary collapse

Methods inherited from Base

#call, #datetime_format=, #serialize_exc, #serialize_trace

Constructor Details

#initialize(app_name = nil, hostname = nil, opts = {}) ⇒ Readable

Intialize a formatter

Parameters:

  • app_name (String) (defaults to: nil)

    application name (execution program name if nil)

  • hostname (String) (defaults to: nil)

    hostname (hostname if nil)

  • opts (Hash) (defaults to: {})

    the initial values of attributes

Options Hash (opts):

  • :trace_indent (String) — default: 4

    the value of trace_indent attribute

  • :trace_max_lines (String) — default: 100

    the value of trace_max_lines attribute

  • :plain (String) — default: false

    the value of plain attribute

  • :excluded_fields (String) — default: []

    the value of excluded_fields attribute



21
22
23
24
25
26
27
28
29
# File 'lib/ougai/formatters/readable.rb', line 21

def initialize(app_name = nil, hostname = nil, opts = {})
  aname, hname, opts = Base.parse_new_params([app_name, hostname, opts])
  super(aname, hname, opts)
  @trace_indent = opts.fetch(:trace_indent, 4)
  @plain = opts.fetch(:plain, false)
  @excluded_fields = opts[:excluded_fields] || []
  @serialize_backtrace = true
  load_dependent
end

Instance Attribute Details

#excluded_fieldsArray<String, Symbol>

The fields excluded from all logs

Returns:

  • (Array<String, Symbol>)

    the current value of excluded_fields



10
11
12
# File 'lib/ougai/formatters/readable.rb', line 10

def excluded_fields
  @excluded_fields
end

#plainBoolean

Whether log should be plain not colorized.

Returns:

  • (Boolean)

    the current value of plain



10
11
12
# File 'lib/ougai/formatters/readable.rb', line 10

def plain
  @plain
end

Instance Method Details

#_call(severity, time, progname, _data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ougai/formatters/readable.rb', line 31

def _call(severity, time, progname, _data)
  data = _data.dup
  msg = data.delete(:msg)
  level = @plain ? severity : colored_level(severity)
  dt = format_datetime(time)
  err_str = create_err_str(data)

  @excluded_fields.each { |f| data.delete(f) }
  data_str = create_data_str(data)
  format_log_parts(dt, level, msg, err_str, data_str)
end

#serialize_backtrace=(value) ⇒ Object

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/ougai/formatters/readable.rb', line 43

def serialize_backtrace=(value)
  raise NotImplementedError, 'Not support serialize_backtrace'
end