-
Notifications
You must be signed in to change notification settings - Fork 38
Logging
This is a quick overview of the logging system.
The logging module provides a way to create messages that are both printed (in color!) in the console and logged to a file. This means that almost all print/debug/info statements can be converted from standard print statements to log statements. The module provides 6 log levels that are called as follows:
log.trace("Some string")
log.debug("Some string")
log.info("Some string")
log.warn("Some string")
log.error("Some string")
log.fatal("Some string")
In the Config_NaoV4.lua file you will see a section on logging like this:
log = {};
log.enableLogFiles = true; --enables writing to file
log.overwriteFiles = true; --overwrites the files every time (clears entire Logs/ folder)
log.logLevel = 'debug'; --order is: trace,debug,info,warn,error,fatal
log.behaviorFile = 'Logs/behavior.txt';
log.teamFile = 'Logs/team.txt';
log.worldFile = 'Logs/world.txt';
log.motionFile = 'Logs/motion.txt';
log.visionFile = 'Logs/vision.txt';
This is where all of the global logging parameters and files are defined.
If you just want log statements to be printed, but not saved to a file, you can disable enableLogFiles.
If you need to run a few runs without the logs being cleared, you can disable overwriting, but make sure to re-enable it when you are done as the logs can get quite large. If you need to save a certain log file for an extended period of time I would suggest copying it over to your computer or some other secure location as the entire folder of Logs gets cleared before each new run. In case anyone in the future needs to know where this overwrite is performed it is in run_arbitrator.lua (line 22 at time of writing).
If you are getting more information printed out than you want to see (or not enough information) you can change to logLevel to the desired level. Anything logged at a lower level than the current logLevel will not be printed or logged. Fatal is the highest level and trace is the lowest level.
If you need to define a new log file, just define it here and make sure to update the file you are trying to log with the new name (see below).
Any file that needs to have access to the logs needs to have the following code near the beginning of the file:
local log = require 'log';
if Config.log.enableLogFiles then
log.outfile = (Config.log.<InsertFileHere>);
end
log.level = Config.log.logLevel;
The first line sets up the local log object so that it can be called using the previously mentioned commands.
The if statement checks to see if LogFiles are enabled and then sets the proper file to log to. Make sure the file is defined in Config_NaoV4.lua and that you are logging to a reasonable file (i.e. don't log to the world file in behavior unless you have a really good reason to!).
The last line sets the global log level so that only statements at or above the current log level get displayed.