module Lumberjack

def context(&block)

Returns:
  • (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?

Returns:
  • (Boolean) -
def context?
  !!Thread.current[:lumberjack_context]
end

def context_tags

Returns:
  • (Hash, nil) -
def context_tags
  context = Thread.current[:lumberjack_context]
  context&.tags
end

def tag(tags)

Returns:
  • (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)

Returns:
  • (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

Returns:
  • (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)

Returns:
  • (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