Class: Occi::Log

Inherits:
Object
  • Object
show all
Includes:
Logger::Severity
Defined in:
lib/occi/log.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_dev) ⇒ Log

creates a new OCCI logger

Parameters:

  • log_dev (IO, String)

    The log device. This is a filename (String) or IO object (typically +STDOUT+, +STDERR+, or an open file).


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/occi/log.rb', line 13

def initialize(log_dev)
  if log_dev.kind_of? Logger
    @logger = log_dev
  else
    @logger = Logger.new(log_dev)
  end

  # subscribe to log messages and send to logger
  @log_subscriber = ActiveSupport::Notifications.subscribe("log") do |name, start, finish, id, payload|
    @logger.log(payload[:level], payload[:message]) if @logger
  end
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger


8
9
10
# File 'lib/occi/log.rb', line 8

def logger
  @logger
end

Class Method Details

.debug(message) ⇒ Object

See Also:


41
42
43
# File 'lib/occi/log.rb', line 41

def self.debug(message)
  ActiveSupport::Notifications.instrument("log", :level => Logger::DEBUG, :message => message)
end

.error(message) ⇒ Object

See Also:


57
58
59
# File 'lib/occi/log.rb', line 57

def self.error(message)
  ActiveSupport::Notifications.instrument("log", :level => Logger::ERROR, :message => message)
end

.fatal(message) ⇒ Object

See Also:


62
63
64
# File 'lib/occi/log.rb', line 62

def self.fatal(message)
  ActiveSupport::Notifications.instrument("log", :level => Logger::FATAL, :message => message)
end

.info(message) ⇒ Object

Log an +INFO+ message

Parameters:

  • message (String)

    the message to log; does not need to be a String


47
48
49
# File 'lib/occi/log.rb', line 47

def self.info(message)
  ActiveSupport::Notifications.instrument("log", :level => Logger::INFO, :message => message)
end

.warn(message) ⇒ Object

See Also:


52
53
54
# File 'lib/occi/log.rb', line 52

def self.warn(message)
  ActiveSupport::Notifications.instrument("log", :level => Logger::WARN, :message => message)
end

Instance Method Details

#closeObject


26
27
28
# File 'lib/occi/log.rb', line 26

def close
  ActiveSupport::Notifications.unsubscribe(@log_subscriber)
end

#levelLogger::Severity

Returns:

  • (Logger::Severity)

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

def level
  @logger.level
end

#level=(severity) ⇒ Object

Parameters:

  • severity (Logger::Severity)

31
32
33
# File 'lib/occi/log.rb', line 31

def level=(severity)
  @logger.level = severity
end