module GemLogger::ContextHandler

Public Instance Methods

add_to_context(key, value) click to toggle source
# File lib/gem_logger/context_handler.rb, line 10
def add_to_context(key, value)
  @context_hash[key.to_s] = value.to_s
end
format_msg_with_context(msg) click to toggle source

Adds the keys/values to the message to be logged in a basic [key=val] format.

# File lib/gem_logger/context_handler.rb, line 19
def format_msg_with_context(msg)
  if @context_hash.keys.length > 0
    msg_context = '['
    @context_hash.each do |k, v|
      msg_context += "#{k}=#{v} "
    end
    msg_context += '] '
    msg = msg.prepend(msg_context)
  end
  msg
end
get_context() click to toggle source

Initializes and returns context hash.

# File lib/gem_logger/context_handler.rb, line 6
def get_context
  @context_hash ||= {}
end
remove_from_context(key) click to toggle source
# File lib/gem_logger/context_handler.rb, line 14
def remove_from_context(key)
  @context_hash.delete(key.to_s)
end