Vita
|
Go to the source code of this file.
Classes | |
class | vita::log |
A basic console printer with integrated logger. More... | |
Namespaces | |
namespace | vita |
The main namespace for the project. | |
Macros | |
#define | vitaDEBUG vitaPRINT(log::lDEBUG) |
#define | vitaERROR vitaPRINT(log::lERROR) |
#define | vitaFATAL vitaPRINT(log::lFATAL) |
#define | vitaINFO vitaPRINT(log::lINFO) |
#define | vitaOUTPUT vitaPRINT(log::lOUTPUT) |
#define | vitaPRINT(level) |
A little trick that makes the code, when logging is not necessary, almost as fast as the code with no logging at all. More... | |
#define | vitaWARNING vitaPRINT(log::lWARNING) |
Definition in file log.h.
#define vitaPRINT | ( | level | ) |
A little trick that makes the code, when logging is not necessary, almost as fast as the code with no logging at all.
Logging will have a cost only if it actually produces output; otherwise, the cost is low (and actually immeasurable in most cases). This lets you control the trade-off between fast execution and detailed logging.
Macro-related dangers should be avoided: we shouldn't forget that the logging code might not be executed at all, subject to the logging level in effect. This is what we actually wanted and is actually what makes the code efficient. But as always, "macro-itis" can introduce subtle bugs. In this example:
vitaPRINT(log::INFO) << "A number of " << NotifyClients() << " were notified.";
the clients will be notified only if the logging level detail will be log::lINFO
and greater. Probably not what was intended! The correct code should be:
const int notifiedClients = NotifyClients(); vitaPRINT(log::lINFO) << "A number of " << notifiedClients << " were notified.";
NDEBUG
is defined all the debug-level logging is eliminated at compile time.