Class: ContextLogger

Inherits:
Logger
  • Object
show all
Includes:
Singleton
Defined in:
lib/tarpaulin/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream = STDOUT) ⇒ ContextLogger

Returns a new instance of ContextLogger.



51
52
53
54
55
# File 'lib/tarpaulin/logger.rb', line 51

def initialize(stream=STDOUT)
  # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
  level=Logger::DEBUG
  super(stream)
end

Class Method Details

.format_blockObject

implicit



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tarpaulin/logger.rb', line 8

def self.format_block # implicit
  the_proc = Proc.new # capture it
  context = eval("Context::determine{}", the_proc) # eval can take a Proc obj or a Binding
  result = the_proc.call # invoke it
  klass = 'nil' # can it be??
  # puts context[:self].inspect
  if context[:self]
    klass = context[:self].class.to_s.split('::').last
    if klass == "Object"; klass = 'main' end
  end
  if context[:function]
    if klass
      context = "#{context[:location]} #{klass}.#{context[:function]}()"
    else
      context = "#{context[:location]} #{context[:function]}()"
    end
  else
    context = "#{context[:location]} #{klass}@#{context[:line_number]}"
  end
  case result
  when String # maybe respond_to? is better but meh ...
    return "[#{context}]: #{result}" # time stamp
  else
    return "[#{context}]: #{result.inspect}"
  end
end