Class: Raykit::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/raykit/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger_array) ⇒ Logger

Returns a new instance of Logger.



6
7
8
9
# File 'lib/raykit/logger.rb', line 6

def initialize(logger_array)
  @logger_array = logger_array
  #@loggerB = loggerB
end

Class Method Details

.console_loggerObject



55
56
57
58
59
60
61
# File 'lib/raykit/logger.rb', line 55

def self.console_logger
  console_logger = ::Logger.new(STDOUT)
  console_logger.formatter = proc do |_severity, _datetime, _progname, msg|
    "#{Raykit::Symbols::get_severity_symbol(_severity)} #{msg}\n"
  end
  console_logger
end

.defaultObject



51
52
53
# File 'lib/raykit/logger.rb', line 51

def self.default
  Raykit::Logger.new([Raykit::Logger::console_logger]) #, Raykit::Logger::file_logger])
end

.file_loggerObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/raykit/logger.rb', line 63

def self.file_logger
  log_dir = Environment::log_dir
  FileUtils.mkdir_p(log_dir) if (!Dir.exist?(log_dir))
  #FileUtils.mkdir("log") if (!Dir.exist?("log"))
  file_logger = ::Logger.new(File.new(LOG_FILENAME, "w"))
  file_logger.formatter = proc do |_severity, _datetime, _progname, msg|
    "#{strip_ansi_codes(msg)}\n"
  end
  file_logger
end

.strip_ansi_codes(str) ⇒ Object

Strips ANSI color codes



47
48
49
# File 'lib/raykit/logger.rb', line 47

def self.strip_ansi_codes(str) # Strips ANSI color codes
  str.gsub(/\e\[[0-9;]*m/, "")
end

Instance Method Details

#debug(message) ⇒ Object



17
18
19
20
21
# File 'lib/raykit/logger.rb', line 17

def debug(message)
  @logger_array.each do |logger|
    logger.debug(message)
  end
end

#error(message) ⇒ Object



35
36
37
38
39
# File 'lib/raykit/logger.rb', line 35

def error(message)
  @logger_array.each do |logger|
    logger.error(message)
  end
end

#fatal(message) ⇒ Object



41
42
43
44
45
# File 'lib/raykit/logger.rb', line 41

def fatal(message)
  @logger_array.each do |logger|
    logger.fatal(message)
  end
end

#info(message) ⇒ Object



23
24
25
26
27
# File 'lib/raykit/logger.rb', line 23

def info(message)
  @logger_array.each do |logger|
    logger.info(message)
  end
end

#level=(level) ⇒ Object



11
12
13
14
15
# File 'lib/raykit/logger.rb', line 11

def level=(level)
  @logger_array.each do |logger|
    logger.level = level
  end
end

#warn(message) ⇒ Object



29
30
31
32
33
# File 'lib/raykit/logger.rb', line 29

def warn(message)
  @logger_array.each do |logger|
    logger.warn(message)
  end
end