Module: Petra::Util::Debug

Defined in:
lib/petra/util/debug.rb

Constant Summary collapse

STRING_COLORS =
{light_gray: 90,
yellow: 33,
green: 32,
red: 31,
purple: 35,
cyan: 36,
blue: 34}.freeze
FORMATS =
{default: 0,
bold: 1,
underline: 4}.freeze

Class Method Summary collapse

Class Method Details

.colored_string(string, color, format) ⇒ Object



38
39
40
# File 'lib/petra/util/debug.rb', line 38

def colored_string(string, color, format)
  "\e[#{Petra::Util::Debug::FORMATS[format]};#{Petra::Util::Debug::STRING_COLORS[color.to_sym]}m#{string}\e[0m"
end

.log(message, level: :debug, color: :light_gray, format: :default) ⇒ Object



26
27
28
# File 'lib/petra/util/debug.rb', line 26

def log(message, level: :debug, color: :light_gray, format: :default)
  logger.send(level, 'Petra :: ' + colored_string(message, color, format))
end

.loggerObject



32
33
34
35
36
# File 'lib/petra/util/debug.rb', line 32

def logger
  @logger ||= Logger.new(STDOUT).tap do |l|
    l.level = "Logger::#{Petra.configuration.log_level.upcase}".constantize
  end
end