Module: Beanpicker::MsgLogger

Included in:
Beanpicker, Server, Worker, Worker::Child
Defined in:
lib/beanpicker.rb

Overview

Abstract logger methods

Instance Method Summary collapse

Instance Method Details

#debug(m) ⇒ Object

call .debug of logger



21
22
23
# File 'lib/beanpicker.rb', line 21

def debug(m)
  log_handler.debug msg(m)
end

#error(m) ⇒ Object

call .error of logger



36
37
38
# File 'lib/beanpicker.rb', line 36

def error(m)
  log_handler.error msg(m)
end

#fatal(m) ⇒ Object

call .fatal of logger



41
42
43
# File 'lib/beanpicker.rb', line 41

def fatal(m)
  log_handler.fatal msg(m)
end

#info(m) ⇒ Object

call .info of logger



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

def info(m)
  log_handler.info msg(m)
end

#log_handlerObject

return the current logger os create a new



55
56
57
# File 'lib/beanpicker.rb', line 55

def log_handler
  @log_handler ||= ::Logger.new(STDOUT)
end

#log_handler=(v) ⇒ Object

set a new logger if the argument is a String/IO it will create a new instance of Logger using it argument else it will see if the argument respond to debug, info, warn, error and fatal



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/beanpicker.rb', line 62

def log_handler=(v)
  if [String, IO].include?(v.class)
    @log_handler = ::Logger.new(v)
  else
    for m in [:debug, :info, :warn, :error, :fatal]
      unless v.respond_to?(m)
        error "Logger #{v} don't respond to #{m}. Aborting!"
        return
      end
    end
    @log_handler = v
  end
end

#msg(msg) ⇒ Object

prepare the message for logger



46
47
48
49
50
51
52
# File 'lib/beanpicker.rb', line 46

def msg(msg)
  if @name
    "[#{name}] #{msg}"
  else
    msg
  end
end

#warn(m) ⇒ Object

call .warn of logger



31
32
33
# File 'lib/beanpicker.rb', line 31

def warn(m)
  log_handler.warn msg(m)
end