[DEV] change log system

This commit is contained in:
Edouard DUPIN 2014-04-30 22:18:00 +02:00
parent 989ced9c90
commit 86116be4db
4 changed files with 43 additions and 15 deletions

View File

@ -19,7 +19,7 @@ ejson::Value::~Value(void) {
clear();
}
etk::CCout& ejson::operator <<(etk::CCout& _os, const ejson::filePos& _obj) {
std::ostream& ejson::operator <<(std::ostream& _os, const ejson::filePos& _obj) {
_os << "(l=";
_os << _obj.getLine();
_os << ",c=";

View File

@ -102,7 +102,7 @@ namespace ejson {
return m_line;
};
};
etk::CCout& operator <<(etk::CCout& _os, const filePos& _obj);
std::ostream& operator <<(std::ostream& _os, const filePos& _obj);
class Value {
public:

View File

@ -8,4 +8,8 @@
#include <ejson/debug.h>
const char * g_ejsonLibName = "ejson ";
int32_t ejson::getLogId(void) {
static int32_t g_val = etk::log::registerInstance("ejson");
return g_val;
}

View File

@ -9,19 +9,43 @@
#ifndef __EJSON_DEBUG_H__
#define __EJSON_DEBUG_H__
#include <etk/types.h>
#include <etk/debugGeneric.h>
#include <etk/log.h>
extern const char * g_ejsonLibName;
namespace ejson {
int32_t getLogId(void);
};
// TODO : Review this problem of multiple intanciation of "std::stringbuf sb"
#define JSON_BASE(info,data) \
do { \
if (info <= etk::log::getLevel(ejson::getLogId())) { \
std::stringbuf sb; \
std::ostream tmpStream(&sb); \
tmpStream << data; \
etk::log::logStream(ejson::getLogId(), info, __LINE__, __class__, __func__, tmpStream); \
} \
} while(0)
#define JSON_CRITICAL(data) ETK_CRITICAL(g_ejsonLibName, data)
#define JSON_WARNING(data) ETK_WARNING(g_ejsonLibName, data)
#define JSON_ERROR(data) ETK_ERROR(g_ejsonLibName, data)
#define JSON_INFO(data) ETK_INFO(g_ejsonLibName, data)
#define JSON_DEBUG(data) ETK_DEBUG(g_ejsonLibName, data)
#define JSON_VERBOSE(data) ETK_VERBOSE(g_ejsonLibName, data)
#define JSON_ASSERT(cond, data) ETK_ASSERT(g_ejsonLibName, cond, data)
#define JSON_CHECK_INOUT(cond) ETK_CHECK_INOUT(g_ejsonLibName, cond)
#define JSON_TODO(cond) ETK_TODO(g_ejsonLibName, cond)
#define JSON_CRITICAL(data) JSON_BASE(1, data)
#define JSON_ERROR(data) JSON_BASE(2, data)
#define JSON_WARNING(data) JSON_BASE(3, data)
#ifdef DEBUG
#define JSON_INFO(data) JSON_BASE(4, data)
#define JSON_DEBUG(data) JSON_BASE(5, data)
#define JSON_VERBOSE(data) JSON_BASE(6, data)
#define JSON_TODO(data) JSON_BASE(4, "TODO : " << data)
#else
#define JSON_INFO(data) do { } while(false)
#define JSON_DEBUG(data) do { } while(false)
#define JSON_VERBOSE(data) do { } while(false)
#define JSON_TODO(data) do { } while(false)
#endif
#define JSON_ASSERT(cond,data) \
do { \
if (!(cond)) { \
JSON_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)
#endif