-
-
Notifications
You must be signed in to change notification settings - Fork 29
Logging
Logging can be done by making use of the class Raz::Logger
. Everything in this class being static, it can't be instantiated.
Logging levels exist to vary the amount of output. There are currently 6 levels: none
, error
, warning
, info
, debug
and all
. Each of these include the ones prior to them: for example, setting the level to warning
will print all error
& warning
messages, but not info
& debug
ones. The special values none
and all
respectively disable or enable every logging output.
// If the logging level is 'error' or higher, will print "[RaZ] [Error] - This is an error message"
Raz::Logger::error("This is an error message");
// If the logging level is 'warning' or higher, will print "[RaZ] [Warning] - This is a warning message"
Raz::Logger::warn("This is a warning message");
// If the logging level is 'info' or higher, will print "[RaZ] [Info] - This is an info message"
Raz::Logger::info("This is an info message");
// If the logging level is 'debug' or higher, will print "[RaZ] [Debug] - This is a debug message"
// In Release mode, this will print nothing by default. To force it, see below
Raz::Logger::debug("This is a debug message");
To change the level, call Raz::Logger::setLoggingLevel(Raz::LoggingLevel::XXX)
, where XXX would be whichever level you want to set.
Logging message with Logger::debug()
could be abused to print useful developer-relevant information, since these by default do absolutely nothing in Release mode.
If you want the 'debug' logging level messages printed even in Release mode, define RAZ_FORCE_DEBUG_LOG
when compiling RaZ. To do so, you can simply add -DRAZ_FORCE_DEBUG_LOG=ON
to CMake's generation command.
If you want to override logging operations, you can define a specific action by calling Raz::Logger::setLoggingFunction(...)
. This can take any function, including lambdas.
Raz::Logger::setLoggingFunction([] (Raz::LoggingLevel level, const std::string& message) {
if (level == Raz::LoggingLevel::ERROR)
std::cout << "Error: ";
std::cout << message << '\n';
});
Raz::Logger::error("Message"); // This will print "Error: Message"
Raz::Logger::info("Message"); // This will print "Message"
To set it back to its original behavior, just call Raz::Logger::resetLoggingFunction()
.
- Home
- How to build RaZ
- Getting started
- General usage knowledge
- Some examples...
- Playground
- Tutorials
- File formats
- Modules
- Debug