8 #ifndef _QI_DETAILS_LOG_HXX_
9 #define _QI_DETAILS_LOG_HXX_
12 #if defined(NO_QI_LOG_DETAILED_CONTEXT) || defined(NDEBUG)
13 # define _qiLogDebug(...) qi::log::LogStream(qi::LogLevel_Debug, "", __FUNCTION__, 0, __VA_ARGS__).self()
15 # define _qiLogDebug(...) qi::log::LogStream(qi::LogLevel_Debug, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
18 #if defined(NO_QI_LOG_DETAILED_CONTEXT) || defined(NDEBUG)
19 # define _qiLogVerbose(...) qi::log::LogStream(qi::LogLevel_Verbose, "", __FUNCTION__, 0, __VA_ARGS__).self()
21 # define _qiLogVerbose(...) qi::log::LogStream(qi::LogLevel_Verbose, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
24 #if defined(NO_QI_LOG_DETAILED_CONTEXT) || defined(NDEBUG)
25 # define _qiLogInfo(...) qi::log::LogStream(qi::LogLevel_Info, "", __FUNCTION__, 0, __VA_ARGS__).self()
27 # define _qiLogInfo(...) qi::log::LogStream(qi::LogLevel_Info, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
30 #if defined(NO_QI_LOG_DETAILED_CONTEXT) || defined(NDEBUG)
31 # define _qiLogWarning(...) qi::log::LogStream(qi::LogLevel_Warning, "", __FUNCTION__, 0, __VA_ARGS__).self()
33 # define _qiLogWarning(...) qi::log::LogStream(qi::LogLevel_Warning, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
36 #if defined(NO_QI_LOG_DETAILED_CONTEXT) || defined(NDEBUG)
37 # define _qiLogError(...) qi::log::LogStream(qi::LogLevel_Error, "", __FUNCTION__, 0, __VA_ARGS__).self()
39 # define _qiLogError(...) qi::log::LogStream(qi::LogLevel_Error, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
42 #if defined(NO_QI_LOG_DETAILED_CONTEXT) || defined(NDEBUG)
43 # define _qiLogFatal(...) qi::log::LogStream(qi::LogLevel_Fatal, "", __FUNCTION__, 0, __VA_ARGS__).self()
45 # define _qiLogFatal(...) qi::log::LogStream(qi::LogLevel_Fatal, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
49 # define _QI_FORMAT_ELEM(_, a, elem) % (elem)
51 # define _QI_LOG_FORMAT(Msg, ...) \
52 QI_CAT(_QI_LOG_FORMAT_HASARG_, _QI_LOG_ISEMPTY(__VA_ARGS__))(Msg, __VA_ARGS__)
54 #define _QI_LOG_FORMAT_HASARG_0(Msg, ...) \
55 boost::str(::qi::log::detail::getFormat(Msg) QI_VAARGS_APPLY(_QI_FORMAT_ELEM, _, __VA_ARGS__ ))
57 #define _QI_LOG_FORMAT_HASARG_1(Msg, ...) Msg
59 #define _QI_SECOND(a, ...) __VA_ARGS__
65 # define _QI_LOG_CATEGORY_GET() _qi_log_category
67 #if defined(NO_QI_LOG_DETAILED_CONTEXT) || defined(NDEBUG)
68 # define _QI_LOG_MESSAGE(Type, Message) \
71 if (::qi::log::detail::isVisible(_QI_LOG_CATEGORY_GET(), ::qi::Type)) \
72 ::qi::log::log(::qi::Type, \
73 _QI_LOG_CATEGORY_GET(), \
75 "", __FUNCTION__, 0); \
79 # define _QI_LOG_MESSAGE(Type, Message) \
82 if (::qi::log::detail::isVisible(_QI_LOG_CATEGORY_GET(), ::qi::Type)) \
83 ::qi::log::log(::qi::Type, \
84 _QI_LOG_CATEGORY_GET(), \
86 __FILE__, __FUNCTION__, __LINE__); \
95 # define _QI_LOG_MESSAGE_STREAM(Type, TypeCased, ...) \
96 QI_CAT(_QI_LOG_MESSAGE_STREAM_HASCAT_, _QI_LOG_ISEMPTY( __VA_ARGS__))(Type, TypeCased, __VA_ARGS__)
99 #define _QI_LOG_MESSAGE_STREAM_HASCAT_1(Type, TypeCased, ...) \
100 ::qi::log::detail::isVisible(_QI_LOG_CATEGORY_GET(), ::qi::Type) \
101 && BOOST_PP_CAT(_qiLog, TypeCased)(_QI_LOG_CATEGORY_GET())
105 #define _QI_LOG_MESSAGE_STREAM_HASCAT_0(...) QI_DELAY(_QI_LOG_MESSAGE_STREAM_HASCAT_0) ## _BOUNCE(__VA_ARGS__)
107 #define _QI_LOG_MESSAGE_STREAM_HASCAT_0(...) _QI_LOG_MESSAGE_STREAM_HASCAT_0_BOUNCE(__VA_ARGS__)
111 #define _QI_LOG_MESSAGE_STREAM_HASCAT_0_BOUNCE(Type, TypeCased, cat, ...) \
112 QI_CAT(_QI_LOG_MESSAGE_STREAM_HASCAT_HASFORMAT_, _QI_LOG_ISEMPTY( __VA_ARGS__))(Type, TypeCased, cat, __VA_ARGS__)
116 #define _QI_LOG_MESSAGE_STREAM_HASCAT_HASFORMAT_1(Type, TypeCased, cat, ...) \
117 BOOST_PP_CAT(_qiLog,TypeCased)(cat)
120 #define _QI_LOG_MESSAGE_STREAM_HASCAT_HASFORMAT_0(Type, TypeCased, cat, ...) \
121 BOOST_PP_CAT(_qiLog, TypeCased)(cat, _QI_LOG_FORMAT(__VA_ARGS__))
130 #define _WQI_IS_EMPTY_HELPER___ a,b
131 #define WQI_IS_EMPTY(a,...) QI_CAT_20(QI_LIST_VASIZE,((QI_CAT_22(_WQI_IS_EMPTY_HELPER, QI_CAT_24(QI_CAT_26(_, a), _)))))
133 #define _QI_FIRST_ARG(a, ...) a
134 #define _QI_LOG_ISEMPTY(...) WQI_IS_EMPTY(QI_CAT_18(_, _QI_FIRST_ARG(__VA_ARGS__, 12)))
138 #define _QI_LOG_REVERSE 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0
139 #define _QI_LOG_REVERSEEMPTY 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1
140 #define _QI_LOG_ARGN(a, b, c, d, e, f, g, h, i, N, ...) N
141 #define _QI_LOG_NARG_(dummy, ...) _QI_LOG_ARGN(__VA_ARGS__)
142 #define _QI_LOG_NARG(...) _QI_LOG_NARG_(dummy, ##__VA_ARGS__, _QI_LOG_REVERSE)
143 #define _QI_LOG_ISEMPTY(...) _QI_LOG_NARG_(dummy, ##__VA_ARGS__, _QI_LOG_REVERSEEMPTY)
164 template <
typename T>
189 Category(
const std::string &name)
196 std::vector<qi::LogLevel> levels;
206 return category && level <= category->maxLevel;
216 const char *
function,
218 const char *category)
220 , _category(category)
223 , _function(function)
229 const char *
function,
234 , _categoryType(category)
236 , _function(function)
242 const char *
function,
244 const char *category,
245 const std::string& message)
247 , _category(category)
250 , _function(function)
259 qi::log::log(_logLevel, _category, this->str().c_str(), _file, _function, _line);
261 qi::log::log(_logLevel, _categoryType, this->str(), _file, _function, _line);
270 const char *_category;
273 const char *_function;
283 #endif // _QI_DETAILS_LOG_HXX_
void log(const qi::LogLevel verb, const char *category, const char *msg, const char *file="", const char *fct="", const int line=0)
Log function. You should call qiLog* macros instead.
boost::format getFormat(const std::string &s)
LogStream(const qi::LogLevel level, const char *file, const char *function, const int line, CategoryType category)
detail::Category * CategoryType
unsigned int SubscriberId
bool isVisible(Category *category, qi::LogLevel level)
Each log macro creates a LogStream object.
LogStream(const qi::LogLevel level, const char *file, const char *function, const int line, const char *category)
LogStream. Will log at object destruction.
LogLevel
Log level verbosity.
~LogStream()
LogStream destructor.
bool operator<(bool b, const NullStream &ns)
#define QI_UNUSED(x)
This macro tags a parameter as unused.
LogStream(const qi::LogLevel level, const char *file, const char *function, const int line, const char *category, const std::string &message)
std::ostream & operator<<(std::ostream &os, qi::StreamColor col)