Module: GemLogger::ContextHandler

Extended by:
ActiveSupport::Concern
Defined in:
lib/gem_logger/context_handler.rb

Instance Method Summary collapse

Instance Method Details

#add_to_context(key, value) ⇒ Object



10
11
12
# 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) ⇒ Object

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



19
20
21
22
23
24
25
26
27
28
29
# 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_contextObject

Initializes and returns context hash.



6
7
8
# File 'lib/gem_logger/context_handler.rb', line 6

def get_context
  @context_hash ||= {}
end

#remove_from_context(key) ⇒ Object



14
15
16
# File 'lib/gem_logger/context_handler.rb', line 14

def remove_from_context(key)
  @context_hash.delete(key.to_s)
end