Module: Mongo::Loggable

Overview

Allows objects to easily log operations.

Since:

  • 2.0.0

Constant Summary

PREFIX =

The standard MongoDB log prefix.

Since:

  • 2.0.0

'MONGODB'.freeze

Instance Method Summary collapse

Instance Method Details

#log_debug(message) ⇒ Object

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



35
36
37
# File 'lib/mongo/loggable.rb', line 35

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

#log_error(message) ⇒ Object

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



47
48
49
# File 'lib/mongo/loggable.rb', line 47

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

#log_fatal(message) ⇒ Object

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



59
60
61
# File 'lib/mongo/loggable.rb', line 59

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

#log_info(message) ⇒ Object

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



71
72
73
# File 'lib/mongo/loggable.rb', line 71

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

#log_warn(message) ⇒ Object

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



83
84
85
# File 'lib/mongo/loggable.rb', line 83

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



95
96
97
# File 'lib/mongo/loggable.rb', line 95

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