Class: Log::Forward

Inherits:
Object
  • Object
show all
Includes:
Converter, FakeIO
Defined in:
lib/log/forward.rb

Overview

Forward an IO to an object (object must respond to #puts) Will convert all puts/prints etc. to Log::Entry’s using Log::Converter#convert Example:

$stderr = Log.forward(your_logfile)

Instance Method Summary collapse

Methods included from FakeIO

#<<, #printf, #process_buffer, #puts, #write

Constructor Details

#initialize(to, type = :info) ⇒ Forward

Returns a new instance of Forward.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
# File 'lib/log/forward.rb', line 29

def initialize(to, type=:info)
  raise ArgumentError, "Target must respond to 'puts'" unless to.respond_to?(:puts)
  @to           = to
  @default_type = type
  @buffer       = ""
end

Instance Method Details

#inspectObject



40
41
42
43
44
45
46
47
# File 'lib/log/forward.rb', line 40

def inspect
  "#<%s:%08x %s %s>" %  [
    self.class,
    object_id,
    @default_type,
    @to.inspect
  ]
end

#process(obj) ⇒ Object



36
37
38
# File 'lib/log/forward.rb', line 36

def process(obj)
  @to.puts(obj)
end