Skip to content
Adam Martin edited this page Nov 11, 2019 · 3 revisions

Accessing the logger

To access the default logger, that outputs to stdout and to in game console (actually ESC key to hide/show), you need to get a instance of the logger using spdlog logger registry : spdlog::get("console_log"). then you have some options :

  • Using it a la log4j , assign to a private field and use these field to send log messages. Actually done on a few systems, as we only would have a single instance of the system running.
  • Assign directly to a local variable like auto _log = spdlog::get("console_log");. Useful for method that have many log messages.
  • Call directly the log level method : spdlog::get("console_log")->info("Hello world!");. Useful when you only need to send a log message on a whole block of code.

Levels

The logger have many levels (read spdlog wiki). The typical info, warning, error, debug, trace, and a few other. By default trace and debug levels are disabled, but calling the main executable with the parameter '-v' enables trace level, and with '-vv' enables trace and debug levels.

Writing log messages

Spdlog accepts many ways to format a log message :

  • lib fmt like : _log->error("Error! File {} is corrupt!", filename);
  • simple : _log->info("Rendering system loaded");

By convention, we try to put the class where a error or warning is generated before the rest of the message, like : "[Shader] Error loading shader: debug.vert Can't open file."

GUI console output

The GUI console, have a limited size buffer to avoid eat tons of memory on logs that could no body being reading, so don't worry if you see that old debug/traces not are showed.

The Console class, exposed a few methods to directly print to it :

  • Println(string) - Simple writes unformatted text. Appends a end of line to the end.
  • Printfln(format, args...) - Writes applying classic printf formatting. Appends a end of line to the end.

GUI Console