Class: Autumn::LogFacade

Inherits:
Object
  • Object
show all
Defined in:
lib/autumn/log_facade.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, type, name) ⇒ LogFacade

Creates a new facade for logger that prepends type and name information to each log message.



34
35
36
37
38
39
# File 'lib/autumn/log_facade.rb', line 34

def initialize(logger, type, name)
  @type = type
  @name = name
  @logger = logger
  @stdout = Speciator.instance.season(:logging) == 'debug'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

:nodoc:



41
42
43
44
45
46
47
# File 'lib/autumn/log_facade.rb', line 41

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

Instance Attribute Details

#nameObject (readonly)

The name of the Autumn object.



29
30
31
# File 'lib/autumn/log_facade.rb', line 29

def name
  @name
end

#typeObject (readonly)

The Autumn object type (typically “Stem” or “Leaf”).



27
28
29
# File 'lib/autumn/log_facade.rb', line 27

def type
  @type
end