Class: Vx::Instrumentation::Logger

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

Defined Under Namespace

Classes: Formatter

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device) ⇒ Logger

Returns a new instance of Logger.



11
12
13
# File 'lib/vx/instrumentation/logger.rb', line 11

def initialize(device)
  @device = device
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vx/instrumentation/logger.rb', line 15

def method_missing(sym, *args, &block)
  if @device.respond_to?(sym)
    begin
      @device.send(sym, *args, &block)
    rescue Exception => e
      $stderr.puts "#{e.class.to_s}, #{e.message.inspect} [#{sym.inspect} #{args.inspect}]"
      $stderr.puts e.backtrace.map{|b| "\t#{b}" }.join("\n")
    end
  else
    super
  end
end

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



33
34
35
# File 'lib/vx/instrumentation/logger.rb', line 33

def logger
  @logger
end

Class Method Details

.setup(target) ⇒ Object



35
36
37
38
39
# File 'lib/vx/instrumentation/logger.rb', line 35

def setup(target)
  log = ::Logger.new(target)
  log.formatter = Formatter
  @logger = new(log)
end

Instance Method Details

#respond_to?(sym) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/vx/instrumentation/logger.rb', line 28

def respond_to?(sym)
  @device.respond_to?(sym)
end