Module: RuneRb::Utils::Logging
- Included in:
- IO::Buffer, IO::Message, IO::Validation, Controller
- Defined in:
- lib/rrb/utils/logging.rb
Overview
Constant Summary collapse
- LOG_FILE_PATH =
"#{ENV['RRB_LOG_PATH'] || 'data/logs'}/rune.rb-#{Time.now.strftime('%Y-%m-%d').chomp}.log".freeze
Instance Method Summary collapse
-
#class_name ⇒ Symbol
The class name, un-nested, as a symbol.
-
#err(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) ⇒ Object
(also: #error)
Log error lines.
-
#err!(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) ⇒ Object
(also: #fatal)
Log fatal lines.
-
#log(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) ⇒ Object
(also: #info)
Log info lines.
-
#log!(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) ⇒ Object
(also: #debug, #warn)
Log warning lines.
Instance Method Details
#class_name ⇒ Symbol
The class name, un-nested, as a symbol
22 23 24 |
# File 'lib/rrb/utils/logging.rb', line 22 def class_name self.class.name.split('::').last.to_sym end |
#err(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) ⇒ Object Also known as: error
Log error lines
62 63 64 65 66 67 68 |
# File 'lib/rrb/utils/logging.rb', line 62 def err(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) lines.each do |line| LOG_STDOUT.error(COLORS.magenta.bold("[#{class_name}] ~> #{line}")) if to_stdout LOG_FILE.error(app_name) { "[#{Time.now.strftime('%H:%M')}] #{COLORS.strip(line)}" } if to_file end nil end |
#err!(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) ⇒ Object Also known as: fatal
Log fatal lines
77 78 79 80 81 82 83 |
# File 'lib/rrb/utils/logging.rb', line 77 def err!(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) lines.each do |line| LOG_STDOUT.error(COLORS.red.bold("[#{class_name}] ~> #{line}")) if to_stdout LOG_FILE.fatal(app_name) { "[#{Time.now.strftime('%H:%M')}] #{COLORS.strip(line)}" } if to_file end nil end |
#log(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) ⇒ Object Also known as: info
Log info lines
31 32 33 34 35 36 37 |
# File 'lib/rrb/utils/logging.rb', line 31 def log(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) lines.each do |line| LOG_STDOUT.info(COLORS.white("[#{class_name}] -> #{line}")) if to_stdout LOG_FILE.info(app_name) { "[#{Time.now.strftime('%H:%M')}] #{COLORS.strip(line)}" } if to_file end nil end |
#log!(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) ⇒ Object Also known as: debug, warn
Log warning lines
46 47 48 49 50 51 52 |
# File 'lib/rrb/utils/logging.rb', line 46 def log!(*lines, app_name: @label || 'rune.rb', to_file: true, to_stdout: true) lines.each do |line| LOG_STDOUT.warn(COLORS.yellow("[#{class_name}] -> #{line}")) if to_stdout LOG_FILE.warn(app_name) { "[#{Time.now.strftime('%H:%M')}] #{COLORS.strip(line)}" } if to_file end nil end |