class Sidekiq::Tracer::JsonLogFormatter

Public Class Methods

new(pretty: false) click to toggle source
# File lib/sidekiq/tracer/json_log_formatter.rb, line 6
def initialize(pretty: false)
  @pretty = !!pretty
end

Public Instance Methods

call(severity, time, _progname, msg) click to toggle source
# File lib/sidekiq/tracer/json_log_formatter.rb, line 10
def call(severity, time, _progname, msg)
  MultiJson.dump({
    tms: time.utc.iso8601(3),
    pid: pid,
    tid: format("TID-%s", thread_id),
    cxt: context,
    sev: severity,
    msg: msg,
    trc: trace,
  }, pretty: @pretty) + "\n"
end

Private Instance Methods

context() click to toggle source
# File lib/sidekiq/tracer/json_log_formatter.rb, line 32
def context
  Thread.current[:sidekiq_context]
end
pid() click to toggle source
# File lib/sidekiq/tracer/json_log_formatter.rb, line 24
def pid
  ::Process.pid
end
thread_id() click to toggle source
# File lib/sidekiq/tracer/json_log_formatter.rb, line 28
def thread_id
  Thread.current.object_id.to_s(36)
end
trace() click to toggle source
# File lib/sidekiq/tracer/json_log_formatter.rb, line 36
def trace
  trace_id = Thread.current[:sidekiq_root_trace]
  trace_id.last unless trace_id.nil?
end