module Lumberjack
def context(&block)
-
(Lumberjack::Context)
- The current context if called without a block.
def context(&block) current_context = Thread.current[:lumberjack_context] if block use_context(Context.new(current_context), &block) else current_context || Context.new end end
def context?
-
(Boolean)
-
def context? !!Thread.current[:lumberjack_context] end
def context_tags
-
(Hash, nil)
-
def context_tags context = Thread.current[:lumberjack_context] context&.tags end
def tag(tags)
-
(void)
-
Parameters:
-
tags
(Hash
) -- The tags to set.
def tag(tags) context = Thread.current[:lumberjack_context] context&.tag(tags) end
def unit_of_work(id = nil)
-
(void)
-
Parameters:
-
id
(String
) -- The id for the unit of work.
def unit_of_work(id = nil) id ||= SecureRandom.hex(6) context do context[:unit_of_work_id] = id yield end end
def unit_of_work_id
-
(String, nil)
- The id for the current unit of work.
def unit_of_work_id context[:unit_of_work_id] end
def use_context(context, &block)
-
(Object)
- The result of the block.
Parameters:
-
context
(Lumberjack::Context
) -- The context to use within the block.
def use_context(context, &block) current_context = Thread.current[:lumberjack_context] begin Thread.current[:lumberjack_context] = (context || Context.new) yield ensure Thread.current[:lumberjack_context] = current_context end end