Class: OpenVZ::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/openvz/log.rb

Overview

A simple class that allows logging at various levels.

Class Method Summary collapse

Class Method Details

.debug(msg) ⇒ Object

Logs at debug level



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

def debug(msg)
    log(:debug, msg)
end

.error(msg) ⇒ Object

Logs at error level



32
33
34
# File 'lib/openvz/log.rb', line 32

def error(msg)
    log(:error, msg)
end

.fatal(msg) ⇒ Object

Logs at fatal level



27
28
29
# File 'lib/openvz/log.rb', line 27

def fatal(msg)
    log(:fatal, msg)
end

.fromObject

filename that called us



50
51
52
# File 'lib/openvz/log.rb', line 50

def from
    from = File.basename(caller[2])
end

.info(msg) ⇒ Object

Logs at info level



12
13
14
# File 'lib/openvz/log.rb', line 12

def info(msg)
    log(:info, msg)
end

.log(level, msg) ⇒ Object

logs message at level



37
38
39
40
41
42
# File 'lib/openvz/log.rb', line 37

def log(level, msg)
    if @known_levels.index(level) <= @known_levels.index(@active_level)
        t = Time.new.strftime("%H:%M:%S")
        STDERR.puts "#{t}: #{level}: #{from}: #{msg}"
    end
end

.set_level(level) ⇒ Object

Set the log level.



45
46
47
# File 'lib/openvz/log.rb', line 45

def set_level(level)
    @active_level = level
end

.warn(msg) ⇒ Object

Logs at warn level



17
18
19
# File 'lib/openvz/log.rb', line 17

def warn(msg)
    log(:warn, msg)
end