Class: Ougai::Formatters::Pino
- Includes:
- ForJson
- Defined in:
- lib/ougai/formatters/pino.rb
Overview
A JSON formatter compatible with pino
Instance Attribute Summary
Attributes included from ForJson
Attributes inherited from Base
#app_name, #hostname, #serialize_backtrace, #trace_indent, #trace_max_lines
Instance Method Summary collapse
- #_call(severity, time, progname, data) ⇒ Object
- #convert_time(data) ⇒ Object
- #datetime_format=(val) ⇒ Object
- #flat_err(data) ⇒ Object
-
#initialize(app_name = nil, hostname = nil, opts = {}) ⇒ Pino
constructor
Intialize a formatter.
Methods inherited from Base
#call, #serialize_exc, #serialize_trace
Constructor Details
#initialize(app_name = nil, hostname = nil, opts = {}) ⇒ Pino
Intialize a formatter
20 21 22 23 24 25 26 |
# File 'lib/ougai/formatters/pino.rb', line 20 def initialize(app_name = nil, hostname = nil, opts = {}) aname, hname, opts = Base.parse_new_params([app_name, hostname, opts]) super(aname, hname, opts) init_opts_for_json(opts) @trace_indent = opts.fetch(:trace_indent, 4) @serialize_backtrace = true end |
Instance Method Details
#_call(severity, time, progname, data) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ougai/formatters/pino.rb', line 32 def _call(severity, time, progname, data) flat_err(data) dump({ name: progname || @app_name, hostname: @hostname, pid: $$, level: to_level(severity), time: time, v: 1 }.merge(data)) end |
#convert_time(data) ⇒ Object
55 56 57 |
# File 'lib/ougai/formatters/pino.rb', line 55 def convert_time(data) data[:time] = (data[:time].to_f * 1000).to_i end |
#datetime_format=(val) ⇒ Object
28 29 30 |
# File 'lib/ougai/formatters/pino.rb', line 28 def datetime_format=(val) raise NotImplementedError, 'Not support datetime_format attribute' unless val.nil? end |
#flat_err(data) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ougai/formatters/pino.rb', line 44 def flat_err(data) return unless data.key?(:err) err = data.delete(:err) msg = err[:message] data[:type] ||= 'Error' data[:msg] ||= msg stack = "#{err[:name]}: #{msg}" stack += "\n" + (" " * @trace_indent) + err[:stack] if err.key?(:stack) data[:stack] ||= stack end |