Module: GemLogger::Log4rHandler::ContextHandler

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

Instance Method Summary collapse

Instance Method Details

#add_to_context(key, value) ⇒ Object



16
17
18
# File 'lib/gem_logger/log4r_handler/context_handler.rb', line 16

def add_to_context(key, value)
  Log4r::MDC.put(key.to_s, value.to_s)
end

#format_msg_with_context(msg) ⇒ Object

No formatting needed, Log4r will handle it.



25
26
27
# File 'lib/gem_logger/log4r_handler/context_handler.rb', line 25

def format_msg_with_context(msg)
  msg
end

#get_contextObject

Log4r::MDC.get_context returns a copy of the log context that is not modified when we remove the context variables added



12
13
14
# File 'lib/gem_logger/log4r_handler/context_handler.rb', line 12

def get_context
  Log4r::MDC.get_context
end

#remove_from_context(key) ⇒ Object



20
21
22
# File 'lib/gem_logger/log4r_handler/context_handler.rb', line 20

def remove_from_context(key)
  Log4r::MDC.remove(key.to_s)
end