module AiGames::Logger

The Logger is a simple logging facility that is indented to be used by bots in any competition by The AI Games. It provides four log levels (DEBUG, INFO, WARN and ERROR) and writes the logs to STDERR, where they are picked up by The AI Games’ game engines.

Update the version for every release.

Constants

DEBUG
ERROR
INFO
VERSION
WARN

Attributes

output[W]

Sets the output stream the logger uses. For tests, pass StringIO.new. If you do not initialize the output stream, $stderr is used.

Public Class Methods

debug(log) click to toggle source

Prints a debug log. If the log level is not set to debug, no action is taken.

# File lib/ai_games/logger.rb, line 39
def debug(log)
  output.puts log if log_level <= DEBUG
end
debug?() click to toggle source

Returns true if the log level is currently set to DEBUG. Use this before calling ‘Logger.debug(log)` to prevent the unnecessary (and costly) creation of strings.

# File lib/ai_games/logger.rb, line 33
def debug?
  DEBUG == log_level
end
error(log) click to toggle source

Prints an error log.

# File lib/ai_games/logger.rb, line 56
def error(log)
  output.puts log if log_level <= ERROR
end
info(log) click to toggle source

Prints an info log. If the log level is not set to info or lower, no action is taken.

# File lib/ai_games/logger.rb, line 45
def info(log)
  output.puts log if log_level <= INFO
end
log_level() click to toggle source

Returns the log level. If the log level has not been set, the default log level is returned.

# File lib/ai_games/logger.rb, line 21
def log_level
  @log_level ||= WARN
end
log_level=(log_level) click to toggle source

Sets the log level. Available options are DEBUG, INFO, WARN,ERROR.

# File lib/ai_games/logger.rb, line 26
def log_level=(log_level)
  @log_level = log_level if [DEBUG, INFO, WARN, ERROR].include?(log_level)
end
warn(log) click to toggle source

Prints a warn log. If the log level is not set to warn or lower, no action is taken.

# File lib/ai_games/logger.rb, line 51
def warn(log)
  output.puts log if log_level <= WARN
end

Private Class Methods

output() click to toggle source

Returns the output stream. If the logger has not been initializes with an output stream, $stderr is returned.

# File lib/ai_games/logger.rb, line 64
def output
  @output ||= $stderr
end