Sha256: ec092d1cc480ef10145833ed71ae8c1bd401f7254a59a86d64352d12397441a5

Contents?: true

Size: 1.64 KB

Versions: 14

Compression:

Stored size: 1.64 KB

Contents

# Defines the Autumn::LogFacade class, which makes it easier for Stems and
# Leaves to add their information to outgoing log messages.

module Autumn
  
  # This class is a facade for Ruby's +Logger+ that adds additional information
  # to log entries. LogFacade will pass any method calls onto a Logger instance,
  # but reformat log entries to include an Autumn object's type and name.
  #
  # For example, if you wanted a LogFacade for a Leaf named "Scorekeeper", you
  # could instantiate one:
  #
  #  facade = LogFacade.new(logger, 'Leaf', 'Scorekeeper')
  #
  # And a call such as:
  #
  #  facade.info "Starting up"
  #
  # Would be reformatted as "Scorekeeper (Leaf): Starting up".
  #
  # In addition, this class will log messages to STDOUT if the +debug+ global
  # option is set. Instantiation of this class is handled by Genesis and should
  # not normally be done by the user.
  
  class LogFacade
    # The Autumn object type (typically "Stem" or "Leaf").
    attr :type
    # The name of the Autumn object.
    attr :name
    
    # Creates a new facade for +logger+ that prepends type and name information
    # to each log message.
    
    def initialize(logger, type, name)
      @type = type
      @name = name
      @logger = logger
      @stdout = Speciator.instance.season(:logging) == 'debug'
    end
    
    def method_missing(meth, *args) # :nodoc:
      if args.size == 1 and args.only.kind_of? String then
        args = [ "#{name} (#{type}): #{args.only}" ]
      end
      @logger.send meth, *args
      puts (args.first.kind_of?(Exception) ? (args.first.to_s + "\n" + args.first.backtrace.join("\n")) : args.first) if @stdout
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
bougyman-autumn-3.1.1 lib/autumn/log_facade.rb
bougyman-autumn-3.1.10 lib/autumn/log_facade.rb
bougyman-autumn-3.1.11 lib/autumn/log_facade.rb
bougyman-autumn-3.1.3 lib/autumn/log_facade.rb
bougyman-autumn-3.1.4 lib/autumn/log_facade.rb
bougyman-autumn-3.1.6 lib/autumn/log_facade.rb
bougyman-autumn-3.1.7 lib/autumn/log_facade.rb
bougyman-autumn-3.1.8 lib/autumn/log_facade.rb
bougyman-autumn-3.1.9 lib/autumn/log_facade.rb
comboy-autumn-3.1 lib/autumn/log_facade.rb
autumn-3.1.11 lib/autumn/log_facade.rb
autumn-3.1.10 lib/autumn/log_facade.rb
autumn-3.1.8 lib/autumn/log_facade.rb
autumn-3.1.9 lib/autumn/log_facade.rb