module RooOnRails::ContextLogging::Formatter
Public Instance Methods
call(severity, timestamp, progname, msg)
click to toggle source
Calls superclass method
# File lib/roo_on_rails/context_logging.rb, line 26 def call(severity, timestamp, progname, msg) super(severity, timestamp, progname, "#{msg}#{context_text}") end
clear_context!()
click to toggle source
# File lib/roo_on_rails/context_logging.rb, line 43 def clear_context! current_context.clear end
with(**context) { |self| ... }
click to toggle source
# File lib/roo_on_rails/context_logging.rb, line 30 def with(**context) Thread.handle_interrupt(Exception => :never) do current_context.push(context) begin Thread.handle_interrupt(Exception => :immediate) do yield self end ensure current_context.pop end end end
Private Instance Methods
context_text()
click to toggle source
# File lib/roo_on_rails/context_logging.rb, line 55 def context_text context = current_context return nil if context.empty? merged_context = context.each_with_object({}) { |ctx, acc| acc.merge!(ctx) } ' ' + Logfmt.dump(merged_context) end
current_context()
click to toggle source
# File lib/roo_on_rails/context_logging.rb, line 49 def current_context # We use our object ID here to avoid conflicting with other instances thread_key = @logging_context_key ||= "roo_on_rails:logging_context:#{object_id}".freeze Thread.current[thread_key] ||= [] end