module Ichnite
Vendored from lograge. Source: github.com/roidrage/lograge/blob/master/lib/lograge/formatters/key_value.rb License: MIT
Constants
- VERSION
Public Class Methods
augment(&blk)
click to toggle source
# File lib/ichnite.rb, line 19 def self.augment(&blk) @augments ||= [] @augments << blk end
context(event)
click to toggle source
# File lib/ichnite.rb, line 10 def self.context(event) c = { event: event.to_s } @augments.each { |a| c.merge!(a.call) } if defined?(@augments) if Thread.current[:ichnite_context] c.merge!(Thread.current[:ichnite_context]) end c end
default_logger()
click to toggle source
# File lib/ichnite.rb, line 45 def self.default_logger @default_logger ||= if defined?(::Rails) && ::Rails.respond_to?(:logger) Ichnite::Logger.new(::Rails.logger) else inner = ::Logger.new($stdout) inner.formatter = proc { |_level, _time, _prog, msg| "#{msg}\n" } Ichnite::Logger.new(inner) end end
default_logger=(logger)
click to toggle source
# File lib/ichnite.rb, line 56 def self.default_logger=(logger) @default_logger = logger end
enter(context) { || ... }
click to toggle source
# File lib/ichnite.rb, line 24 def self.enter(context) Thread.current[:ichnite_context] ||= {} Thread.current[:ichnite_context].merge!(context) if block_given? begin yield ensure leave(*context.keys) end end end
leave(*context_keys)
click to toggle source
# File lib/ichnite.rb, line 37 def self.leave(*context_keys) if context_keys.empty? Thread.current[:ichnite_context] = {} else context_keys.each {|k| Thread.current[:ichnite_context].delete k } end end
log(event, opts = {})
click to toggle source
# File lib/ichnite.rb, line 6 def self.log(event, opts = {}) default_logger.log(event, opts) end