module GemLogger::LoggerSupport::ContextLoggerCommon

Public Instance Methods

context(added_context) click to toggle source

@param [Hash] added_context - A hash containing context that will be added to the log messages produced by the returned logger @returns [LogContextLogger] - logger with the added context

# File lib/gem_logger/logger_support.rb, line 62
def context(added_context)
  LogContextLogger.new(self.logger, self.log_context.merge(added_context)).extend(GemLogger.context_handler)
end
event_context(event_type) click to toggle source

Adds an event_type to the context @param [Symbol] event_type - The event type, which will be added to the context of this log statement

# File lib/gem_logger/logger_support.rb, line 68
def event_context(event_type)
  context(:event_type => event_type)
end
exception_context(exception) click to toggle source

Adds an exception class to the context @param [Exception] exception

# File lib/gem_logger/logger_support.rb, line 74
def exception_context(exception)
  context(:exception => exception.class.to_s)
end
log_exception(e, message, options = {}) click to toggle source

Logs an exception, including the backtrace. @param [Exception] exception @param [String] message @option [Symbol] :level - The log level to log the message at (default :error)

# File lib/gem_logger/logger_support.rb, line 82
def log_exception(e, message, options = {})
  level = options.delete(:level) || :error
  backtrace = e.backtrace.try{ |b| b.join("\n") } || '(no backtrace)'
  exception_context(e).send(level, "#{message}: #{e} #{backtrace}")
end