Class: Fit4Ruby::ILogger

Inherits:
Monitor
  • Object
show all
Includes:
Singleton
Defined in:
lib/fit4ruby/Log.rb

Overview

The ILogger class is a singleton that provides a common logging mechanism to all objects. It exposes essentially the same interface as the Logger class, just as a singleton and with some additional methods like ‘fatal’ and ‘cricital’.

Constant Summary collapse

@@logger =
Logger.new(STDOUT)

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Pass all calls to unknown methods to the @@logger object.



45
46
47
# File 'lib/fit4ruby/Log.rb', line 45

def method_missing(method, *args, &block)
  @@logger.send(method, *args, &block)
end

Instance Method Details

#fatal(msg, &block) ⇒ Object

Print an error message via the Logger and raise and Fit4Ruby::Error. code 1.

Raises:



56
57
58
59
# File 'lib/fit4ruby/Log.rb', line 56

def fatal(msg, &block)
  @@logger.error(msg, &block)
  raise Error, msg
end

#open(io) ⇒ Object

Redirect all log messages to the given IO.

Parameters:

  • io (IO)

    Output file descriptor



35
36
37
38
39
40
41
42
# File 'lib/fit4ruby/Log.rb', line 35

def open(io)
  begin
    @@logger = Logger.new(io)
  rescue => e
    @@logger = Logger.new(STDERR)
    Log.fatal "Cannot open log file: #{e.message}"
  end
end

#respond_to?(method, include_private = false) ⇒ Boolean

Make it properly introspectable.

Returns:

  • (Boolean)


50
51
52
# File 'lib/fit4ruby/Log.rb', line 50

def respond_to?(method, include_private = false)
  @@logger.respond_to?(method)
end