Class: Boxlet::Log

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, level, rotation = 10, max_size = 1024000) ⇒ Log

The levels are:

UNKNOWN: An unknown message that should always be logged.
FATAL: An unhandleable error that results in a program crash.
ERROR: A handleable error condition.
WARN: A warning.
INFO: Generic (useful) information about system operation.
DEBUG: Low-level information for developers.


17
18
19
20
21
22
23
24
25
26
# File 'lib/boxlet/log.rb', line 17

def initialize(filename, level, rotation=10, max_size=1024000)
  # create the directory for the log if it doesn't exist
  if !File.exist? File.dirname(filename)
    FileUtils.mkdir_p File.dirname(filename)
  end

  @log ||= Logger.new(filename, rotation, max_size)
  @log.level = level
  @log
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



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

def log
  @log
end

Instance Method Details

#write(level, message) ⇒ Object

Possible levels: (:debug, :info, :warn, :error, :fatal)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/boxlet/log.rb', line 29

def write(level, message)
  if Boxlet.debug?
    if message.is_a? String
      puts message
    else
      pp message
    end
  else
    if level == :info
      pp message
    end
    @log.call(level, message)
  end
end