Sha256: c46f8ef4bf78999e762d5d781085a3ff3dea9e424d2b2f861950564e73e6aa5f

Contents?: true

Size: 911 Bytes

Versions: 4

Compression:

Stored size: 911 Bytes

Contents

require 'active_support/core_ext/module/attribute_accessors'
require 'madvertise/ext/environment'
require 'madvertise-logging'

##
# The {Logging} module provides a global container for the logger object.
#
module Logging
  mattr_accessor :logger
  self.logger = nil

  # @private
  def self.create_logger
    if Env.prod?
      Madvertise::Logging::ImprovedLogger.new(:syslog, $0)
    else
      Madvertise::Logging::ImprovedLogger.new(STDERR, $0)
    end.tap do |logger|
      logger.level = :info
    end
  end

  ##
  # The {Logging::Helpers} module is mixed into the Object class to make the
  # logger available to every object in the system.
  #
  module Helpers

    # Retreive and possibly create the global logger object.
    #
    # @return [Logger]  The logger object.
    def log
      ::Logging.logger ||= ::Logging.create_logger
    end
  end
end

class ::Object
  include ::Logging::Helpers
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
madvertise-ext-0.2.2 lib/madvertise/ext/logging.rb
madvertise-ext-0.2.0 lib/madvertise/ext/logging.rb
madvertise-ext-0.1.3 lib/madvertise/ext/logging.rb
madvertise-ext-0.1.2 lib/madvertise/ext/logging.rb