Class: Liri::Common::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/common/log.rb

Constant Summary collapse

FOLDER_NAME =
'logs'
FOLDER_PATH =
File.join(Dir.pwd, "/#{FOLDER_NAME}")
FILE_NAME =
'liri.log'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shift_age, folder_path:, file_name:, stdout: true) ⇒ Log

Returns a new instance of Log.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/common/log.rb', line 19

def initialize(shift_age, folder_path:, file_name:, stdout: true)
  @stdout = stdout
  @shift_age = shift_age
  @folder_path = folder_path || FOLDER_PATH
  @file_name = file_name || FILE_NAME
  @file_path = File.join(@folder_path, '/', @file_name)

  create_stdout_logger if @stdout
  create_log_folder
  create_file_logger
end

Instance Attribute Details

#folder_pathObject (readonly)

Returns the value of attribute folder_path.



17
18
19
# File 'lib/common/log.rb', line 17

def folder_path
  @folder_path
end

Instance Method Details

#debug(text, stdout = false) ⇒ Object



31
32
33
34
35
# File 'lib/common/log.rb', line 31

def debug(text, stdout = false)
  puts(ColorizeText.debug(text)) if stdout
  @stdout_logger.debug(text) if @stdout
  @file_logger.debug(text)
end

#error(text, stdout = false) ⇒ Object



49
50
51
52
53
# File 'lib/common/log.rb', line 49

def error(text, stdout = false)
  puts(ColorizeText.error(text)) if stdout
  @stdout_logger.error(text) if @stdout
  @file_logger.error(text)
end

#fatal(text, stdout = false) ⇒ Object



55
56
57
58
59
# File 'lib/common/log.rb', line 55

def fatal(text, stdout = false)
  puts(ColorizeText.fatal(text)) if stdout
  @stdout_logger.fatal(text) if @stdout
  @file_logger.fatal(text)
end

#info(text, stdout = false) ⇒ Object



37
38
39
40
41
# File 'lib/common/log.rb', line 37

def info(text, stdout = false)
  puts(ColorizeText.default(text)) if stdout
  @stdout_logger.info(text) if @stdout
  @file_logger.info(text)
end

#unknown(text, stdout = false) ⇒ Object



61
62
63
64
65
# File 'lib/common/log.rb', line 61

def unknown(text, stdout = false)
  puts(ColorizeText.unknown(text)) if stdout
  @stdout_logger.unknown(text) if @stdout
  @file_logger.unknown(text)
end

#warn(text, stdout = false) ⇒ Object



43
44
45
46
47
# File 'lib/common/log.rb', line 43

def warn(text, stdout = false)
  puts(ColorizeText.warn(text)) if stdout
  @stdout_logger.warn(text) if @stdout
  @file_logger.warn(text)
end