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.



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

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

Instance Method Details

#abort(msg, &block) ⇒ Object

Print an error message via the Logger and raise a Fit4Ruby::Abort. This method should be used to abort the program in case of user errors.

Raises:



60
61
62
63
# File 'lib/fit4ruby/Log.rb', line 60

def abort(msg, &block)
  @@logger.error(msg, &block)
  raise Abort, msg
end

#fatal(msg, &block) ⇒ Object

Print an error message via the Logger and raise a Fit4Ruby::Error. This method should be used to abort the program in case of program logic errors.

Raises:



68
69
70
71
# File 'lib/fit4ruby/Log.rb', line 68

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



39
40
41
42
43
44
45
46
# File 'lib/fit4ruby/Log.rb', line 39

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)


54
55
56
# File 'lib/fit4ruby/Log.rb', line 54

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