Module: Tina4::Debug

Defined in:
lib/tina4/debug.rb

Constant Summary collapse

LEVELS =
{
  "[TINA4_LOG_ALL]" => Logger::DEBUG,
  "[TINA4_LOG_DEBUG]" => Logger::DEBUG,
  "[TINA4_LOG_INFO]" => Logger::INFO,
  "[TINA4_LOG_WARNING]" => Logger::WARN,
  "[TINA4_LOG_ERROR]" => Logger::ERROR,
  "[TINA4_LOG_NONE]" => Logger::FATAL
}.freeze
COLORS =
{
  reset: "\e[0m", red: "\e[31m", green: "\e[32m",
  yellow: "\e[33m", blue: "\e[34m", magenta: "\e[35m",
  cyan: "\e[36m", gray: "\e[90m"
}.freeze

Class Method Summary collapse

Class Method Details

.debug(message, *args) ⇒ Object



40
41
42
# File 'lib/tina4/debug.rb', line 40

def debug(message, *args)
  log(:debug, message, *args)
end

.error(message, *args) ⇒ Object



48
49
50
# File 'lib/tina4/debug.rb', line 48

def error(message, *args)
  log(:error, message, *args)
end

.info(message, *args) ⇒ Object



36
37
38
# File 'lib/tina4/debug.rb', line 36

def info(message, *args)
  log(:info, message, *args)
end

.setup(root_dir = Dir.pwd) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tina4/debug.rb', line 23

def setup(root_dir = Dir.pwd)
  log_dir = File.join(root_dir, "logs")
  FileUtils.mkdir_p(log_dir)
  log_file = File.join(log_dir, "debug.log")
  @file_logger = Logger.new(log_file, 10, 5 * 1024 * 1024)
  @file_logger.level = Logger::DEBUG
  @console_logger = Logger.new($stdout)
  @console_logger.level = resolve_level
  @console_logger.formatter = method(:color_formatter)
  @file_logger.formatter = method(:plain_formatter)
  @initialized = true
end

.warning(message, *args) ⇒ Object



44
45
46
# File 'lib/tina4/debug.rb', line 44

def warning(message, *args)
  log(:warn, message, *args)
end