Class: HerdstWorker::Log::Facade

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level = "DEBUG", progname = DEFAULT_PROGNAME, single_line = false) ⇒ Facade

Returns a new instance of Facade.



17
18
19
20
21
22
23
24
# File 'lib/herdst_worker/log/facade.rb', line 17

def initialize(level = "DEBUG", progname = DEFAULT_PROGNAME, single_line = false)
    self.progname = progname
    self.single_line = single_line
    
    self.logger = Logger.new(STDOUT)
    self.logger.progname = self.get_progname(progname)
    self.set_log_level(level)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/herdst_worker/log/facade.rb', line 58

def method_missing(name)
    full_name = self.progname === DEFAULT_PROGNAME ? 
        name : 
        "#{self.progname}.#{name}"
    
    Facade.new(self.level, full_name, self.single_line)
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



14
15
16
# File 'lib/herdst_worker/log/facade.rb', line 14

def level
  @level
end

#loggerObject

Returns the value of attribute logger.



14
15
16
# File 'lib/herdst_worker/log/facade.rb', line 14

def logger
  @logger
end

#prognameObject

Returns the value of attribute progname.



14
15
16
# File 'lib/herdst_worker/log/facade.rb', line 14

def progname
  @progname
end

#single_lineObject

Returns the value of attribute single_line.



14
15
16
# File 'lib/herdst_worker/log/facade.rb', line 14

def single_line
  @single_line
end

Instance Method Details

#debug(*attributes) ⇒ Object



33
34
35
# File 'lib/herdst_worker/log/facade.rb', line 33

def debug(*attributes)
    write_message :debug, attributes
end

#error(*attributes) ⇒ Object



48
49
50
# File 'lib/herdst_worker/log/facade.rb', line 48

def error(*attributes)
    write_message :error, attributes
end

#fatal(*attributes) ⇒ Object



53
54
55
# File 'lib/herdst_worker/log/facade.rb', line 53

def fatal(*attributes)
    write_message :fatal, attributes
end

#info(*attributes) ⇒ Object



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

def info(*attributes)
    write_message :info, attributes
end

#set_log_level(level) ⇒ Object



27
28
29
30
# File 'lib/herdst_worker/log/facade.rb', line 27

def set_log_level(level)
    self.level = level
    self.logger.level = Logger.const_get(level)
end

#warn(*attributes) ⇒ Object



43
44
45
# File 'lib/herdst_worker/log/facade.rb', line 43

def warn(*attributes)
    write_message :warn, attributes
end

#write_message(type, message) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/herdst_worker/log/facade.rb', line 67

def write_message(type, message)
    if self.single_line
        full_message = message.map { |i| i.to_s }.join(" ")
    else
        full_message = message.map { |i| i.to_s }.join("\n")
    end
    
    self.logger.send(type, full_message)
end