Class: Ougai::Formatters::Base

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/ougai/formatters/base.rb

Direct Known Subclasses

Bunyan, Readable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name = nil, hostname = nil) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
# File 'lib/ougai/formatters/base.rb', line 11

def initialize(app_name = nil, hostname = nil)
  @app_name = app_name || File.basename($0, ".rb")
  @hostname = hostname || Socket.gethostname.force_encoding('UTF-8')
  @trace_indent = 2
  @trace_max_lines = 100
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



9
10
11
# File 'lib/ougai/formatters/base.rb', line 9

def app_name
  @app_name
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



9
10
11
# File 'lib/ougai/formatters/base.rb', line 9

def hostname
  @hostname
end

#trace_indentObject

Returns the value of attribute trace_indent.



8
9
10
# File 'lib/ougai/formatters/base.rb', line 8

def trace_indent
  @trace_indent
end

#trace_max_linesObject

Returns the value of attribute trace_max_lines.



8
9
10
# File 'lib/ougai/formatters/base.rb', line 8

def trace_max_lines
  @trace_max_lines
end

Instance Method Details

#serialize_exc(ex) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/ougai/formatters/base.rb', line 18

def serialize_exc(ex)
  err = {
    name: ex.class.name,
    message: ex.to_s
  }
  if ex.backtrace
    err[:stack] = serialize_trace(ex.backtrace)
  end
  err
end

#serialize_trace(trace) ⇒ Object



29
30
31
32
# File 'lib/ougai/formatters/base.rb', line 29

def serialize_trace(trace)
  sp = "\n" + ' ' * @trace_indent
  trace.slice(0, @trace_max_lines).join(sp)
end