Class: Log::Logger

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

Overview

Singleton Class to logging debugging and error states in logfile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#logObject

Returns the value of attribute log.



6
7
8
# File 'lib/log/logger.rb', line 6

def log
  @log
end

Class Method Details

.initialize_logger(file_name, log_level) ⇒ Object

Initializing and configuring the logger object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/log/logger.rb', line 23

def self.initialize_logger(file_name, log_level)
  @log = Log4r::Logger.new("xen_log")

  @log.outputters = Log4r::Outputter.stdout

  file = Log4r::FileOutputter.new('fileOutputter', :filename => file_name, :trunc => true)


  @log.add(file)
  @log.level = self.convert_loglevel(log_level)
  format = Log4r::PatternFormatter.new(:pattern => "[%l] %d :: %m")
  file.formatter = format
end

.log(options = {:log_level => 1}, filename = "/tmp/xen-gem.log") ⇒ Object

Check if exists a logging class. If not i’ll be create

Params

  • filename : Path and filename of logdatei

  • log_level : Which loglevel are using



13
14
15
16
17
18
19
20
# File 'lib/log/logger.rb', line 13

def self.log(options = {:log_level => 1}, filename = "/tmp/xen-gem.log")
  if @log
    return @log
  else
    initialize_logger(filename, options[:log_level])
    return @log
  end
end