123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Loggable

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Defined in: lib/mongoid/loggable.rb

Overview

Contains logging behavior.

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#loggerLogger (rw)

Note:

Will try to grab Rails’ logger first before creating a new logger with stderr.

Get the logger.

Examples:

Get the logger.

Loggable.logger

Returns:

  • (Logger)

    The logger.

[ GitHub ]

  
# File 'lib/mongoid/loggable.rb', line 18

def logger
  return @logger if defined?(@logger)
  @logger = rails_logger || default_logger
end

#logger=(logger) ⇒ Logger (rw)

::Set the logger.

Examples:

::Set the logger.

Loggable.logger = Logger.new(STDERR)

Parameters:

  • logger (Logger)

    The logger to set.

Returns:

  • (Logger)

    The new logger.

[ GitHub ]

  
# File 'lib/mongoid/loggable.rb', line 31

def logger=(logger)
  @logger = logger
end

Instance Method Details

#default_loggerLogger (private)

This method is for internal use only.

Gets the default ::Mongoid logger - stderr.

Examples:

Get the default logger.

Loggable.default_logger

Returns:

  • (Logger)

    The default logger.

[ GitHub ]

  
# File 'lib/mongoid/loggable.rb', line 45

def default_logger
  logger = Logger.new(STDERR)
  logger.level = Mongoid::Config.log_level
  logger
end

#rails_loggerLogger (private)

This method is for internal use only.

Get the ::Rails logger if loaded in a ::Rails application, otherwise nil.

Examples:

Get Rails’ logger.

Loggable.rails_logger

Returns:

  • (Logger)

    The Rails logger.

[ GitHub ]

  
# File 'lib/mongoid/loggable.rb', line 59

def rails_logger
  if defined?(::Rails)
    ::Rails.logger
  else
    nil
  end
end