forked from ducttape/ducttape-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Logging
opatut edited this page Jul 31, 2011
·
2 revisions
The ducttape logging framework is very powerful. You can use it in your game to output information on the console, in a file or to any other std::ostream.
There can be several Loggers, each of which can have several LogStreams (i.e. log levels, e.g. "debug" or "warning"), each of which has a format and a stream associated and can be disabled.
LogStream names are case-insensitive.
// Get a Logger. Loggers are created on-demand.
dt::Logger& custom_logger = dt::Logger::Get("custom_logger_name");
dt::Logger& default_logger = dt::Logger::Get(); // equivalent: dt::Logger::Get("default")
// Get a LogStream.
dt::LogStream* default_debug = default_logger.GetStream("debug");
dt::LogStream* default_error = default_logger.GetStream("error");
// Set the format.
default_debug->SetFormat("Logger [%1$s] logs on Stream [%2$s] message: %3$s");
// Output a message.
default_debug->Output(&default_logger, "Some default debug output");
// Set stream for LogStream "error"
default_error->SetStream(&std::cerr);
Use printf syntax for the format strings. The following replacements will be made:
- Logger name
- Stream name
- Message
There are shortcuts for outputting messages on the streams "debug", "info", "warning" and "error":
dt::Logger::Get().Debug("Unimportant debug message");
dt::Logger::Get().Info("Just some information");
dt::Logger::Get().Warning("It is getting serious!");
dt::Logger::Get().Error("Critical run-time error.");
Terminals that support ANSI colors can use the following static string members of dt::LogStream
in the format string to color all following characters:
- COLOR_RED
- COLOR_GREEN
- COLOR_YELLOW
- COLOR_BLUE
- COLOR_PURPLE
- COLOR_CYAN
- COLOR_NONE