iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Logging and error/information message facility

Logging functions provide facilities o very easily issue messages to the console or other stream. These messages can inform the user or can be used during code development for debugging purposes.

Classes

class  nrt::GenericLog< LogLevelPolicy >
 A generic logging class. More...
 
class  nrt::exception::FatalException
 Fatal exception class that is thronw by NRT_FATAL(msg) and others using the nrt::FatalLevelPolicy. More...
 

Modules

 Log Output Policies
 
 Log Level Policies
 

Macros

#define NRT_DEBUG(msg)
 Convenience macro for users to print out console messages, DEBUG level. More...
 
#define NRT_INFO(msg)
 Convenience macro for users to print out console messages, INFO level. More...
 
#define NRT_WARNING(msg)
 Convenience macro for users to print out console messages, WARNING level. More...
 
#define NRT_FATAL(msg)
 Convenience macro for users to print out console messages, FATAL level. More...
 
#define NRT_FMT_DEBUG(FORMAT,...)
 Convenience macro to print out a log message using printf syntax, DEBUG level. More...
 
#define NRT_FMT_INFO(FORMAT,...)
 Convenience macro to print out a log message using printf syntax, INFO level. More...
 
#define NRT_FMT_WARNING(FORMAT,...)
 Convenience macro to print out a log message using printf syntax, WARNING level. More...
 
#define NRT_FMT_FATAL(FORMAT,...)
 Convenience macro to print out a log message using printf syntax, FATAL level. More...
 
#define NRT_MODDEBUG(msg)
 Debugging macro use internally by core model-related code. More...
 
#define NRT_BBDEBUG(msg)
 Debugging macro used internally by core blackboard-related code. More...
 

Variables

int nrt::currentLogLevel
 Current log level, default is 6 (LOG_INFO) More...
 
nrt::Component *const nrt_component_this
 Global shadow variable for log messages issued outside of nrt::Component objects. More...
 

Macro Definition Documentation

#define NRT_DEBUG (   msg)

Convenience macro for users to print out console messages, DEBUG level.

This macro is intended to be used with a stream-oriented syntax for everything that is passed as argument to the macro. The syntax is a bit strange at first but you will rapidly get used to it. This allows any datatype that has an operator<< defined to be printed out in a log (contrary to printf-style syntax). For example:

int x = 3; std::string str = "hello"; nrt::Rectangle<int> rect;
NRT_DEBUG("x=" << x << " and str=" << str << " and rect=" << rect);
Note
This is the preferred way to issue messages in NRT. Do you use printf, do not use cout<<"blah", etc.

By design, your log message will not be evaluated if the current log level is below (stronger) than the debug level. This means that you should not be afraid of wasting CPU computing messages that will not be output; for example:

NRT_DEBUG("CPU-intensive function says: " << cpu_intensive_function());

will not run the cpu-intensive function if the current log level is warning. This also means that you should never assume that your log message will be evaluated. For example:

int x = 42;
NRT_DEBUG("x = " << (x++) );
// x may now be 43 or 42 depending on current log level...
Examples:
tests/test-Async.C, tests/test-Module.C, tests/test-ResultsSyntax.C, tests/test-split-messages.C, tests/test-ThreadPool.C, and tests/test-TransformManager.C.

Definition at line 113 of file Log.H.

Referenced by main(), MyModule::onMessage(), and MyModule::tryCheck().

#define NRT_FATAL (   msg)
#define NRT_FMT_DEBUG (   FORMAT,
  ... 
)

Convenience macro to print out a log message using printf syntax, DEBUG level.

This macro behaves like printf, for example:

int x = 3; float y = 2.0F;
NRT_FMT_DEBUG("x=%d and y=%f", x, y);
Note
In general, NRT_DEBUG(msg) is preferred as it can handle any C++ type that has a conversion to string, as opposed to only the few POD types supported by the printf syntax.

Definition at line 155 of file Log.H.

#define NRT_FMT_INFO (   FORMAT,
  ... 
)

Convenience macro to print out a log message using printf syntax, INFO level.

Usage syntax is the same as for NRT_FMT_DEBUG(FORMAT, ...)

Definition at line 163 of file Log.H.

#define NRT_FMT_WARNING (   FORMAT,
  ... 
)

Convenience macro to print out a log message using printf syntax, WARNING level.

Usage syntax is the same as for NRT_FMT_DEBUG(FORMAT, ...)

Definition at line 171 of file Log.H.

#define NRT_FMT_FATAL (   FORMAT,
  ... 
)

Convenience macro to print out a log message using printf syntax, FATAL level.

Usage syntax is the same as for NRT_FMT_DEBUG(FORMAT, ...)

Note
After printing the message, this also throws nrt::exception::FatalException

Definition at line 180 of file Log.H.

#define NRT_MODDEBUG (   msg)
Value:

Debugging macro use internally by core model-related code.

To see debug messages that are internal to Model Component/Parameter operations, define NRT_MODDEBUG to not be commented out. You need to clean and recompile everything for and change in the definition to take effect.

Note
Only people writing core Model-related code should use NRT_MODDEBUG(), all others use NRT_DEBUG(msg).

Definition at line 190 of file Log.H.

Referenced by nrt::Manager::addComponent(), nrt::Blackboard::addModule(), nrt::Component::addSubComponent(), nrt::Module::addSubModule(), nrt::Manager::removeComponent(), nrt::Component::removeSubComponent(), and nrt::Module::removeSubModule().

#define NRT_BBDEBUG (   msg)
Value:

Debugging macro used internally by core blackboard-related code.

To see debug messages that are internal to the Blackboard's operation, define NRT_BBDEBUG to not be commented out. You need to clean and recompile everything for and change in the definition to take effect.

Note
Only people writing core Blackboard-related code should use NRT_BBDEBUG(), all others use NRT_DEBUG(msg).

Definition at line 200 of file Log.H.

Referenced by nrt::MessageSubscriberCore< Subscription >::abortSplitReceive(), nrt::MessageCheckerCore< Checking >::check(), nrt::MessagePosterCore< Posting >::createSubPosters(), nrt::MessageSubscriberCore< Subscription >::createSubSubscribers(), nrt::MessagePosterCore< Posting >::deleteSubPosters(), nrt::MessageSubscriberCore< Subscription >::deleteSubSubscribers(), and nrt::Blackboard::removeModule().

Variable Documentation

int nrt::currentLogLevel

Current log level, default is 6 (LOG_INFO)

The log level is set by changing the value of this global variable. The default value is LOG_WARNING=4, and other valid values include LOG_INFO=6, LOG_DEBUG=7, LOG_BBDEBUG=8. To change the log level, one would simply write, for example in your main function:

currentLogLevel = 7; // switch to verbose LOG_DEBUG log level
Examples:
tests/test-Log.C.
nrt::Component* const nrt_component_this

Global shadow variable for log messages issued outside of nrt::Component objects.

This global variable is only necessary to perform some trickery with the above logging functions. If any of these logging functions are called from within a Component, there is a public member Component* called nrt_component_this that will be passed into the GenericLog constructor. If the logging functions are called from outside of a Component, then this global nrt_component_this will be in scope, and will be inserted instead.