Sha256: a6acea0dfaa8eca969081085cec5c3e9cdcb56411fc57d6373896fbcdfb35b74

Contents?: true

Size: 1.39 KB

Versions: 22

Compression:

Stored size: 1.39 KB

Contents

# encoding: utf-8
module Mongoid

  # Contains logging behaviour.
  module Loggable

    # Get the logger.
    #
    # @note Will try to grab Rails' logger first before creating a new logger
    #   with stdout.
    #
    # @example Get the logger.
    #   Loggable.logger
    #
    # @return [ Logger ] The logger.
    #
    # @since 3.0.0
    def logger
      return @logger if defined?(@logger)
      @logger = rails_logger || default_logger
    end

    # Set the logger.
    #
    # @example Set the logger.
    #   Loggable.logger = Logger.new($stdout)
    #
    # @param [ Logger ] The logger to set.
    #
    # @return [ Logger ] The new logger.
    #
    # @since 3.0.0
    def logger=(logger)
      @logger = logger
    end

    private

    # Gets the default Mongoid logger - stdout.
    #
    # @api private
    #
    # @example Get the default logger.
    #   Loggable.default_logger
    #
    # @return [ Logger ] The default logger.
    #
    # @since 3.0.0
    def default_logger
      logger = Logger.new($stdout)
      logger.level = Mongoid::Config.log_level
      logger
    end

    # Get the Rails logger if it's defined.
    #
    # @api private
    #
    # @example Get Rails' logger.
    #   Loggable.rails_logger
    #
    # @return [ Logger ] The Rails logger.
    #
    # @since 3.0.0
    def rails_logger
      defined?(::Rails) && ::Rails.respond_to?(:logger) && ::Rails.logger
    end
  end
end

Version data entries

22 entries across 21 versions & 3 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/loggable.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/loggable.rb
mongoid-5.2.1 lib/mongoid/loggable.rb
tdiary-5.0.4 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/loggable.rb
mongoid-6.1.0 lib/mongoid/loggable.rb
mongoid-5.2.0 lib/mongoid/loggable.rb
mongoid-5.2.0.rc0 lib/mongoid/loggable.rb
mongoid-6.1.0.rc0 lib/mongoid/loggable.rb
mongoid-6.0.3 lib/mongoid/loggable.rb
mongoid-5.1.6 lib/mongoid/loggable.rb
mongoid-6.0.2 lib/mongoid/loggable.rb
mongoid-6.0.1 lib/mongoid/loggable.rb
mongoid-5.1.5 lib/mongoid/loggable.rb
mongoid-6.0.0 lib/mongoid/loggable.rb
mongoid-5.1.4 lib/mongoid/loggable.rb
mongoid-6.0.0.rc0 lib/mongoid/loggable.rb
mongoid-6.0.0.beta lib/mongoid/loggable.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-5.1.3/lib/mongoid/loggable.rb
mongoid-5.1.3 lib/mongoid/loggable.rb
mongoid-5.1.2 lib/mongoid/loggable.rb