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
# File 'lib/fusuma/multi_logger.rb', line 18

def initialize
  filepath = self.class.instance_variable_get('@filepath')
  if filepath
    logfile = File.new(filepath, 'a')
    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



54
55
56
# File 'lib/fusuma/multi_logger.rb', line 54

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

.error(msg) ⇒ Object



62
63
64
# File 'lib/fusuma/multi_logger.rb', line 62

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

.info(msg) ⇒ Object



50
51
52
# File 'lib/fusuma/multi_logger.rb', line 50

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

.warn(msg) ⇒ Object



58
59
60
# File 'lib/fusuma/multi_logger.rb', line 58

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

Instance Method Details

#debug(msg) ⇒ Object



31
32
33
34
35
# File 'lib/fusuma/multi_logger.rb', line 31

def debug(msg)
  return unless debug_mode?

  super(msg)
end

#debug_mode?Boolean

Returns:

  • (Boolean)


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

def debug_mode?
  debug_mode
end

#error(msg) ⇒ Object



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

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

#warn(msg) ⇒ Object



37
38
39
# File 'lib/fusuma/multi_logger.rb', line 37

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