Skip to content

Add a proper logging system #12

@nasso

Description

@nasso

Due to the complexity of a game engine, logging is pretty much required to keep track of what's going on. Currently, everything is written directly to the standard outputs using std::cout and std::cerr. A proper logging system would instead allow us to write log messages anywhere (e.g. to a file on disk, send them over the network, or display them in an in-game console).

Most game engines have some way handling logging with various levels of verbosity. The most common levels available are:

  1. Critical error messages
  2. Warning messages
  3. General purpose information
  4. Debugging messages
  5. Trace (very verbose)

These levels are commonly identified by an integer like in the ordered list above. The logger then has routines to filter messages to the ones we are interested in only.

Proposed interface

Setting the current log level should probably be just a function call with an enum value:

using ige::log::LogLevel;

ige::log::set_log_level(LogLevel::DEBUG);

An idiomatic C++ interface for logging messages could look like the following:

ige::log::error << "Error";
ige::log::warn << "Warning" ;
ige::log::info << "Information";
ige::log::debug << "Debug message";
ige::log::trace << "Low level trace that won't be shown";

However, some logging libraries prefer C-style IO for performance reasons.

Either way, effort should be made to be as lazy as possible for disabled log levels. Writing to ige::log::trace should be as light as possible when the current logging level is lower than TRACE.

Some popular logging libraries in the C++ world:

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions