Class: Fate::MultiLogger::Sublogger

Inherits:
Object
  • Object
show all
Defined in:
lib/fate/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(master, name) ⇒ Sublogger

Returns a new instance of Sublogger.



24
25
26
27
28
# File 'lib/fate/logger.rb', line 24

def initialize(master, name)
  @master = master
  @io = @master.io
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/fate/logger.rb', line 38

def method_missing(method, *args, &block)
  if @master.respond_to?(method)
    # insert this logger's name into every relayed call.
    @master.send(method, @name, *args, &block)
  elsif @io.respond_to?(method)
    @io.send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#write(string) ⇒ Object

duck typing for IO



31
32
33
34
35
36
# File 'lib/fate/logger.rb', line 31

def write(string)
  return 0 unless string
  num = @io.write(@master.format(@name, string))
  @io.flush
  num
end