class Howitzer::Log

This class represents logger

Public Class Methods

new() click to toggle source
# File lib/howitzer/log.rb, line 74
def initialize
  @logger = Logger.new('ruby_log')
  @logger.add(console_log)
  @logger.add(error_log)
  self.base_formatter = default_formatter
  Logger['ruby_log'].level = Howitzer.debug_mode ? ALL : INFO
  Logger['ruby_log'].trace = true
end

Public Instance Methods

debug(msg) click to toggle source

Outputs debug message if Howitzer.debug_mode == true @param msg [String] a message

# File lib/howitzer/log.rb, line 20
def debug(msg)
  @logger.debug(msg)
end
error(msg) click to toggle source

Outputs error message @param msg [String] a message

# File lib/howitzer/log.rb, line 41
def error(msg)
  @logger.error(msg)
end
fatal(msg) click to toggle source

Outputs fatal message @param msg [String] a message

# File lib/howitzer/log.rb, line 48
def fatal(msg)
  @logger.fatal(msg)
end
info(msg) click to toggle source

Outputs info message @param msg [String] a message

# File lib/howitzer/log.rb, line 27
def info(msg)
  @logger.info(msg)
end
print_feature_name(text) click to toggle source

Outputs a feature name into the log with INFO severity @param text [String] a feature name

print_scenario_name(text) click to toggle source

Outputs a scenario name into log with INFO severity @param text [String] a scenario name

settings_as_formatted_text() click to toggle source

Outputs formatted howitzer settings

# File lib/howitzer/log.rb, line 61
def settings_as_formatted_text
  log_without_formatting { info ::SexySettings::Base.instance.as_formatted_text }
end
warn(msg) click to toggle source

Outputs warn message @param msg [String] a message

# File lib/howitzer/log.rb, line 34
def warn(msg)
  @logger.warn(msg)
end

Private Instance Methods

base_formatter=(formatter) click to toggle source

:nocov:

# File lib/howitzer/log.rb, line 116
def base_formatter=(formatter)
  @logger.outputters.each { |outputter| outputter.formatter = formatter }
end
blank_formatter() click to toggle source

:nocov:

# File lib/howitzer/log.rb, line 100
def blank_formatter
  PatternFormatter.new(pattern: '%m')
end
console_log() click to toggle source

:nocov:

# File lib/howitzer/log.rb, line 91
def console_log
  StdoutOutputter.new(:console).tap { |o| o.only_at(INFO, DEBUG, WARN) }
end
default_formatter() click to toggle source

:nocov:

# File lib/howitzer/log.rb, line 106
def default_formatter
  params = if Howitzer.hide_datetime_from_log
             { pattern: '[%l] %m' }
           else
             { pattern: '%d [%l] :: %m', date_pattern: '%Y/%m/%d %H:%M:%S' }
           end
  PatternFormatter.new(params)
end
error_log() click to toggle source
# File lib/howitzer/log.rb, line 95
def error_log
  StderrOutputter.new(:error, 'level' => ERROR)
end
log_without_formatting() { || ... } click to toggle source

:nocov:

# File lib/howitzer/log.rb, line 84
def log_without_formatting
  self.base_formatter = blank_formatter
  yield
  self.base_formatter = default_formatter
end