Vita
Classes | Namespaces | Macros
log.h File Reference

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)
 

Detailed Description

Remarks
This file is part of VITA.
License\n
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/

Definition in file log.h.

Macro Definition Documentation

◆ vitaDEBUG

#define vitaDEBUG   vitaPRINT(log::lDEBUG)

Definition at line 110 of file log.h.

◆ vitaERROR

#define vitaERROR   vitaPRINT(log::lERROR)

Definition at line 111 of file log.h.

◆ vitaFATAL

#define vitaFATAL   vitaPRINT(log::lFATAL)

Definition at line 109 of file log.h.

◆ vitaINFO

#define vitaINFO   vitaPRINT(log::lINFO)

Definition at line 112 of file log.h.

◆ vitaOUTPUT

#define vitaOUTPUT   vitaPRINT(log::lOUTPUT)

Definition at line 113 of file log.h.

◆ vitaPRINT

#define vitaPRINT (   level)
Value:
if (level < log::reporting_level);\
else log().get(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.";
Note
When the NDEBUG is defined all the debug-level logging is eliminated at compile time.

Definition at line 105 of file log.h.

◆ vitaWARNING

#define vitaWARNING   vitaPRINT(log::lWARNING)

Definition at line 114 of file log.h.