Class: Jerakia::Log

Inherits:
Jerakia show all
Defined in:
lib/jerakia/log.rb

Constant Summary

Constants inherited from Jerakia

VERSION

Instance Attribute Summary

Attributes inherited from Jerakia

#launcher, #options

Instance Method Summary collapse

Methods inherited from Jerakia

#config, fatal, #log, #lookup

Constructor Details

#initialize(level = :info, file = '/var/log/jerakia.log') ⇒ Log

Returns a new instance of Log


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jerakia/log.rb', line 3

def initialize(level = :info, file = '/var/log/jerakia.log')
  begin
    @@logger = Logger.new(file)
  rescue Errno::EACCES, Errno::ENOENT => e
    @@logger = Logger.new(STDOUT)
    info("Failed to open logfile: #{e.message}, logs will be directed to STDOUT")
  end

  @@level = level
  case @@level
  when :verbose
    @@logger.level = Logger::INFO
  when :info
    @@logger.level = Logger::INFO
  when :debug
    @@logger.level = Logger::DEBUG
  end
end

Instance Method Details

#debug(msg) ⇒ Object


34
35
36
# File 'lib/jerakia/log.rb', line 34

def debug(msg)
  @@logger.debug msg
end

#error(msg) ⇒ Object


38
39
40
# File 'lib/jerakia/log.rb', line 38

def error(msg)
  @@logger.error msg
end

#fatal(msg) ⇒ Object


42
43
44
# File 'lib/jerakia/log.rb', line 42

def fatal(msg)
  @@logger.fatal msg
end

#info(msg) ⇒ Object


30
31
32
# File 'lib/jerakia/log.rb', line 30

def info(msg)
  @@logger.info msg
end

#loggerObject


22
23
24
# File 'lib/jerakia/log.rb', line 22

def logger
  @@logger
end

#verbose(msg) ⇒ Object


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

def verbose(msg)
  @@logger.info msg if @@level == :verbose
end