Module: GamespyQuery::Tools

Defined in:
lib/gamespy_query/base.rb

Constant Summary collapse

STR_EMPTY =
""
CHAR_N =
"\n"

Class Method Summary collapse

Class Method Details

.dbg_msg(e) ⇒ Object



21
22
23
24
# File 'lib/gamespy_query/base.rb', line 21

def dbg_msg(e)
  "#{e.class}: #{e.message if e.respond_to?(:backtrace)}
BackTrace: #{e.backtrace.join(CHAR_N) unless !e.respond_to?(:backtrace) || e.backtrace.nil?}"
end

.debug(&block) ⇒ Object



37
38
39
40
41
42
# File 'lib/gamespy_query/base.rb', line 37

def debug(&block)
  return unless DEBUG
  logger.debug yield
rescue Exception => e
  puts "Error: #{e.class} #{e.message}, #{e.backtrace.join("\n")}"
end

.log_exception(e, as_error = true, msg = "") ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/gamespy_query/base.rb', line 27

def log_exception(e, as_error = true, msg = "")
  if defined?(::Tools)
    ::Tools.log_exception(e, as_error, msg)
  else
    puts "Error: #{e.class} #{e.message}, #{e.backtrace.join("\n")}"
    logger.error "#{"#{msg}:" unless msg.empty?}#{e.class} #{e.message}" if as_error
    logger.debug dbg_msg(e)
  end
end

.loggerObject



17
18
19
# File 'lib/gamespy_query/base.rb', line 17

def logger
  @logger ||= if defined?(::Tools); ::Tools.logger; else; defined?(ActionController) ? ActionController::Base.logger || Logger.new("logger.log") : Logger.new("logger.log"); end
end