Build Status Coverage Status


Allows classes/modules in gems to have logger class/instance methods with a pluggable Logger implementation


Include the GemLogger::Logger concern into the classes that need to be able to log. By default, it will use the standard Ruby logger, if you need a different logger, then configure GemLogger like:

GemLogger.configure do |config|

  # The default logger instance to use
  # (optional, defaults to 
  config.default_logger =

  # module to include when GemLogger::Logger is included
  # (optional, defaults to GemLogger::BasicLogger) 
  config.logger_concern = SomeModule



It is also possible to add context to your log messages through the context call:

MyClass.logger.context(:key => 'value').debug("I want context here")

as well as include backtraces and context to exceptions by calling the log_exception method with the error and a custom message:

MyClass.logger.log_exception('uh oh'), 'This is bad')

By default, log_exception uses the ERROR level, but also accepts a level as an option:

MyClass.logger.log_exception('uh oh'), 'This is bad', {:level => :debug})

Unless otherwise specified, the context is added to the beginning of the log message in a basic key = value format. You can, however, define your own context handler, and pass it in on initialization:

GemLogger.configure do |config|
  config.context_handler = MyHandler

The class should implement: get_context - initialize and return the context add_to_context(key, val) - add a given value to the context at key remove_from_context(key) - remove the key from the context format_msg_with_context(msg) - takes the base log message and adds the context to it, returning the final message.