123456789_123456789_123456789_123456789_123456789_

Module: Mongo::Loggable

Overview

Allows objects to easily log operations.

Since:

  • 2.0.0

Constant Summary

Instance Method Summary

Instance Method Details

#_mongo_log_prefix (private)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/loggable.rb', line 108

def _mongo_log_prefix
  (respond_to?(:options) && options && options[:log_prefix]) || PREFIX
end

#format_message(message) (private)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/loggable.rb', line 104

def format_message(message)
  format("%s | %s".freeze, _mongo_log_prefix, message)
end

#log_debug(message)

Convenience method to log debug messages with the standard prefix.

Examples:

Log a debug message.

log_debug('Message')

Parameters:

  • message (String)

    The message to log.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/loggable.rb', line 38

def log_debug(message)
  logger.debug(format_message(message)) if logger.debug?
end

#log_error(message)

Convenience method to log error messages with the standard prefix.

Examples:

Log a error message.

log_error('Message')

Parameters:

  • message (String)

    The message to log.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/loggable.rb', line 50

def log_error(message)
  logger.error(format_message(message)) if logger.error?
end

#log_fatal(message)

Convenience method to log fatal messages with the standard prefix.

Examples:

Log a fatal message.

log_fatal('Message')

Parameters:

  • message (String)

    The message to log.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/loggable.rb', line 62

def log_fatal(message)
  logger.fatal(format_message(message)) if logger.fatal?
end

#log_info(message)

Convenience method to log info messages with the standard prefix.

Examples:

Log a info message.

log_info('Message')

Parameters:

  • message (String)

    The message to log.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/loggable.rb', line 74

def log_info(message)
  logger.info(format_message(message)) if logger.info?
end

#log_warn(message)

Convenience method to log warn messages with the standard prefix.

Examples:

Log a warn message.

log_warn('Message')

Parameters:

  • message (String)

    The message to log.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/loggable.rb', line 86

def log_warn(message)
  logger.warn(format_message(message)) if logger.warn?
end

#loggerLogger

Get the logger instance.

Examples:

Get the logger instance.

loggable.logger

Returns:

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/loggable.rb', line 98

def logger
  ((respond_to?(:options) && options && options[:logger]) || Logger.logger)
end