Class: Fusuma::MultiLogger

Inherits:
Logger
  • Object
show all
Includes:
Singleton
Defined in:
lib/fusuma/multi_logger.rb

Overview

logger separate between stdout and strerr

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMultiLogger

Returns a new instance of MultiLogger.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fusuma/multi_logger.rb', line 18

def initialize
  filepath = self.class.instance_variable_get(:@filepath)
  if filepath
    logfile = File.new(filepath, "a")
    logfile.sync = true
    super(logfile)
    $stderr = logfile
  else
    super($stdout)
  end
  @err_logger = Logger.new($stderr)
  @debug_mode = false
end

Class Attribute Details

.filepath=(value) ⇒ Object (writeonly)

Sets the attribute filepath

Parameters:

  • value

    the value to set the attribute filepath to.



15
16
17
# File 'lib/fusuma/multi_logger.rb', line 15

def filepath=(value)
  @filepath = value
end

Instance Attribute Details

#debug_modeObject

Returns the value of attribute debug_mode.



12
13
14
# File 'lib/fusuma/multi_logger.rb', line 12

def debug_mode
  @debug_mode
end

#err_loggerObject (readonly)

Returns the value of attribute err_logger.



11
12
13
# File 'lib/fusuma/multi_logger.rb', line 11

def err_logger
  @err_logger
end

Class Method Details

.debug(msg) ⇒ Object



71
72
73
# File 'lib/fusuma/multi_logger.rb', line 71

def debug(msg)
  instance.debug(msg)
end

.error(msg) ⇒ Object



79
80
81
# File 'lib/fusuma/multi_logger.rb', line 79

def error(msg)
  instance.error(msg)
end

.info(msg) ⇒ Object



67
68
69
# File 'lib/fusuma/multi_logger.rb', line 67

def info(msg)
  instance.info(msg)
end

.warn(msg) ⇒ Object



75
76
77
# File 'lib/fusuma/multi_logger.rb', line 75

def warn(msg)
  instance.warn(msg)
end

Instance Method Details

#debug(msg) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/fusuma/multi_logger.rb', line 32

def debug(msg)
  return unless debug_mode?

  return if ignore_pattern?(msg)

  super(msg)
end

#debug_mode?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/fusuma/multi_logger.rb', line 48

def debug_mode?
  debug_mode
end

#error(msg) ⇒ Object



44
45
46
# File 'lib/fusuma/multi_logger.rb', line 44

def error(msg)
  err_logger.error(msg)
end

#ignore_pattern?(msg) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fusuma/multi_logger.rb', line 52

def ignore_pattern?(msg)
  # TODO: configurable from config.yml
  pattern = /timer_input/
  case msg
  when Hash
    e = msg.values.find { |v| v.is_a? Fusuma::Plugin::Events::Event }
    return unless e

    e.tag.match?(pattern)
  else
    false
  end
end

#warn(msg) ⇒ Object



40
41
42
# File 'lib/fusuma/multi_logger.rb', line 40

def warn(msg)
  err_logger.warn(msg)
end