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



102
103
104
# File 'lib/gem_logger/logger_support.rb', line 102

def log_context
  @log_context
end

#loggerObject

Returns the value of attribute logger

Returns:

  • (Object)

    the current value of logger



102
103
104
# File 'lib/gem_logger/logger_support.rb', line 102

def logger
  @logger
end

Instance Method Details

#log(level, msg) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/gem_logger/logger_support.rb', line 109

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