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
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
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
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
Prints an error log.
# File lib/ai_games/logger.rb, line 56 def error(log) output.puts log if log_level <= ERROR end
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
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
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
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