Skip to content

Using the Logger

Ben Brenkman edited this page Sep 11, 2018 · 2 revisions

The Game Engine has a few tools to help you debug your code. One of these tools is the Logger, it is designed to trace where the debug message came from. This allows you to filter all the messages coming in through the console and focus on the ones that are important to you. It also shows what changes you have made to the code have had what effects on others code.

The logger is fairly simple to use first add the include to your header file

#include "Logger.h"

Instead of using the standard C++ library to output messages for debugging, the logger will take care of which messages are necessary to show when debugging, or when releasing the code. An example output will look something like this.

2018-9-11 09:23:13 [DEBUG][AssetManager] Successfully loaded shader: Shader\bb_vert.glsl

There are several important pieces to each output. The first part 2018-9-11 09:23:13 is the timestamp, it lets us keep track of when the message was given to the Logger, this can be useful in determining when things happen within the code.

The next part [DEBUG] tells us what kind of message we are looking at. There are several different kinds of messages we can receive. DEBUG - for debugging code, WARN - a warning message used if there is something that didn't go quite expected but doesn't break the code, SEVERE and ERROR - used when something went terribly wrong, and INFO - just for displaying random stuff makes it look cool.

Here is an example of the code that is used to log the code given in the above example

Logger::Log<AssetManager>(DEBUG, "Successfully loaded shader: Shader\bb_vert.glsl");

The code follows this format where the Logger::LoggerLevel is the type of message, DEBUG, INFO, WARN, SEVERE, ERROR. And the message is simply a const char* containing the message you want to be logged.

Logger::Log<AssetManager>(Logger::LoggerLevel level, const char* message);

Inside the <> after the Logger::Log put the name of the class you are currently working in. This keeps track of where the message came from and will help in debugging. The timestamp is automatically determined when you call the function.