Module: RuneRb::Utils::Logging

Included in:
IO::Buffer, IO::Message, IO::Validation, Controller
Defined in:
lib/rrb/utils/logging.rb

Overview

Since:

  • 0.0.1

Constant Summary collapse

LOG_FILE_PATH =

Since:

  • 0.0.1

"#{ENV['RRB_LOG_PATH'] || 'data/logs'}/rune.rb-#{Time.now.strftime('%Y-%m-%d').chomp}.log".freeze

Instance Method Summary collapse

Instance Method Details

#class_nameSymbol

The class name, un-nested, as a symbol

Returns:

  • (Symbol)

    the class name.

Since:

  • 0.0.1



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

Parameters:

  • lines (Array)

    lines of text that are passed to the RuneRb::GLOBAL.

  • app_name (String) (defaults to: @label || 'rune.rb')

    the name of the application.

  • to_file (Boolean) (defaults to: true)

    should the line be written to the Logging#LOG_FILE?

  • to_stdout (Boolean) (defaults to: true)

    should the line(s) be written to $STDOUT?

Since:

  • 0.0.1



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

Parameters:

  • lines (Array)

    lines of text that are passed to the RuneRb::GLOBAL.

  • app_name (String) (defaults to: @label || 'rune.rb')

    the name of the application.

  • to_file (Boolean) (defaults to: true)

    should the line be written to the Logging#LOG_FILE?

  • to_stdout (Boolean) (defaults to: true)

    should the line(s) be written to $STDOUT?

Since:

  • 0.0.1



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

Parameters:

  • lines (Array)

    lines of text that are passed to the logger.

  • app_name (String) (defaults to: @label || 'rune.rb')

    the name of the application.

  • to_file (Boolean) (defaults to: true)

    should the line be written to the Logging#LOG_FILE?

  • to_stdout (Boolean) (defaults to: true)

    should the line(s) be written to $STDOUT?

Since:

  • 0.0.1



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

Parameters:

  • lines (Array)

    lines of text that are passed to the RuneRb::GLOBAL.

  • app_name (String) (defaults to: @label || 'rune.rb')

    the name of the application.

  • to_file (Boolean) (defaults to: true)

    should the line be written to the Logging#LOG_FILE?

  • to_stdout (Boolean) (defaults to: true)

    should the line(s) be written to $STDOUT?

Since:

  • 0.0.1



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