utility: added stream logging macros

For easier use with int and other basic types, new logging macros where introduced that use stringstream internally, so
heterogeneous data can be logged using the following syntax:
	LOG_INFO_STREAM(<< "hello " << 42 << '!');
This commit is contained in:
Eberhard Graether
2014-07-21 02:11:07 +02:00
parent 0d46de871a
commit 160e67a94d
4 changed files with 66 additions and 79 deletions
+35 -6
View File
@@ -1,29 +1,58 @@
#ifndef LOGGING_H
#define LOGGING_H
#include <sstream>
#include "utility/logging/LogManager.h"
/**
* @brief Makros to simplify usage of the log manager
*/
#define LOG_INFO(str) \
#define LOG_INFO(__str__) \
do \
{ \
LogManager::getInstance()->logInfo(str, __FILE__, __FUNCTION__, __LINE__); \
LogManager::getInstance()->logInfo(__str__, __FILE__, __FUNCTION__, __LINE__); \
} \
while(0) \
#define LOG_WARNING(str) \
#define LOG_WARNING(__str__) \
do \
{ \
LogManager::getInstance()->logWarning(str, __FILE__, __FUNCTION__, __LINE__); \
LogManager::getInstance()->logWarning(__str__, __FILE__, __FUNCTION__, __LINE__); \
} \
while(0) \
#define LOG_ERROR(str) \
#define LOG_ERROR(__str__) \
do \
{ \
LogManager::getInstance()->logError(str, __FILE__, __FUNCTION__, __LINE__); \
LogManager::getInstance()->logError(__str__, __FILE__, __FUNCTION__, __LINE__); \
} \
while(0) \
#define LOG_INFO_STREAM(__s__) \
do \
{ \
std::stringstream __ss__; \
__ss__ __s__; \
LogManager::getInstance()->logInfo(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \
} \
while(0) \
#define LOG_WARNING_STREAM(__s__) \
do \
{ \
std::stringstream __ss__; \
__ss__ __s__; \
LogManager::getInstance()->logWarning(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \
} \
while(0) \
#define LOG_ERROR_STREAM(__s__) \
do \
{ \
std::stringstream __ss__; \
__ss__ __s__; \
LogManager::getInstance()->logError(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \
} \
while(0) \