Class: GemLogger::LoggerSupport::LogContextLogger

Inherits:
Struct
  • Object
show all
Includes:
ContextLoggerCommon
Defined in:
lib/gem_logger/logger_support.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContextLoggerCommon

#context, #event_context, #exception_context, #log_exception

Instance Attribute Details

#log_contextObject

Returns the value of attribute log_context

Returns:

  • (Object)

    the current value of log_context



95
96
97
# File 'lib/gem_logger/logger_support.rb', line 95

def log_context
  @log_context
end

#loggerObject

Returns the value of attribute logger

Returns:

  • (Object)

    the current value of logger



95
96
97
# File 'lib/gem_logger/logger_support.rb', line 95

def logger
  @logger
end

Instance Method Details

#log(level, msg) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/gem_logger/logger_support.rb', line 103

def log(level, msg)
  existing_context = get_context
  self.log_context.each { |k,v| add_to_context(k, v) }
  msg = format_msg_with_context(msg)
  self.logger.send(level, msg)
ensure
  self.log_context.each { |k,v| remove_from_context(k) }
  existing_context.each { |k,v| add_to_context(k, v) }
end