Class: Ougai::Formatters::Bunyan

Inherits:
Base
  • Object
show all
Includes:
ForJson
Defined in:
lib/ougai/formatters/bunyan.rb

Overview

A JSON formatter compatible with node-bunyan

Instance Attribute Summary collapse

Attributes inherited from Base

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

Instance Method Summary collapse

Methods included from ForJson

#to_level

Methods inherited from Base

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

Constructor Details

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

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: 2

    the value of trace_indent attribute

  • :trace_max_lines (String) — default: 100

    the value of trace_max_lines attribute

  • :serialize_backtrace (String) — default: true

    the value of serialize_backtrace attribute

  • :jsonize (String) — default: true

    the value of jsonize attribute

  • :with_newline (String) — default: true

    the value of with_newline attribute



23
24
25
26
27
28
# File 'lib/ougai/formatters/bunyan.rb', line 23

def initialize(app_name = nil, hostname = nil, opts = {})
  aname, hname, opts = Base.parse_new_params([app_name, hostname, opts])
  super(aname, hname, opts)
  @jsonize = opts.fetch(:jsonize, true)
  @with_newline = opts.fetch(:with_newline, true)
end

Instance Attribute Details

#jsonizeBoolean

Whether log should converts JSON

Returns:

  • (Boolean)

    the current value of jsonize



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

def jsonize
  @jsonize
end

#with_newlineBoolean

Whether tailing NL should be appended

Returns:

  • (Boolean)

    the current value of with_newline



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

def with_newline
  @with_newline
end

Instance Method Details

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



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

def _call(severity, time, progname, data)
  dump({
    name: progname || @app_name,
    hostname: @hostname,
    pid: $$,
    level: to_level(severity),
    time: time,
    v: 0
  }.merge(data))
end