Class: Rbindkeys::LogUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/rbindkeys/log_utils.rb

Constant Summary collapse

DEFAULT_LOG_OUTPUT =
STDOUT
DEFAULT_FORMAT =
:simple
DEFAULT_LEVEL =
Logger::INFO
@@output =
DEFAULT_LOG_OUTPUT
@@format =
DEFAULT_FORMAT
@@level =
DEFAULT_LEVEL

Class Method Summary collapse

Class Method Details

.get_logger(progname) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rbindkeys/log_utils.rb', line 18

def get_logger progname
  logger = Logger.new @@output

  logger.progname = progname
  logger.level = @@level
  set_formatter logger

  logger
end

.set_formatter(logger) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rbindkeys/log_utils.rb', line 28

def set_formatter logger
  case @@format
  when :simple
    logger.formatter = proc do |sev, date, prog, msg|
      "* #{msg}\n"
    end
  when :default
  else
    l = Logger.new STDERR
    l.fatal "unknown logger format"
    exit false
  end
end