8 #ifndef _QI_DETAIL_LOG_HXX_
9 #define _QI_DETAIL_LOG_HXX_
11 #include <boost/format.hpp>
12 #include <boost/noncopyable.hpp>
13 #include <boost/preprocessor/cat.hpp>
15 #if defined(NO_QI_LOG_DETAILED_CONTEXT)
16 # define _qiLogDebug(...) qi::log::LogStream(qi::LogLevel_Debug, "", __FUNCTION__, 0, __VA_ARGS__).self()
18 # define _qiLogDebug(...) qi::log::LogStream(qi::LogLevel_Debug, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
21 #if defined(NO_QI_LOG_DETAILED_CONTEXT)
22 # define _qiLogVerbose(...) qi::log::LogStream(qi::LogLevel_Verbose, "", __FUNCTION__, 0, __VA_ARGS__).self()
24 # define _qiLogVerbose(...) qi::log::LogStream(qi::LogLevel_Verbose, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
27 #if defined(NO_QI_LOG_DETAILED_CONTEXT)
28 # define _qiLogInfo(...) qi::log::LogStream(qi::LogLevel_Info, "", __FUNCTION__, 0, __VA_ARGS__).self()
30 # define _qiLogInfo(...) qi::log::LogStream(qi::LogLevel_Info, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
33 #if defined(NO_QI_LOG_DETAILED_CONTEXT)
34 # define _qiLogWarning(...) qi::log::LogStream(qi::LogLevel_Warning, "", __FUNCTION__, 0, __VA_ARGS__).self()
36 # define _qiLogWarning(...) qi::log::LogStream(qi::LogLevel_Warning, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
39 #if defined(NO_QI_LOG_DETAILED_CONTEXT)
40 # define _qiLogError(...) qi::log::LogStream(qi::LogLevel_Error, "", __FUNCTION__, 0, __VA_ARGS__).self()
42 # define _qiLogError(...) qi::log::LogStream(qi::LogLevel_Error, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
45 #if defined(NO_QI_LOG_DETAILED_CONTEXT)
46 # define _qiLogFatal(...) qi::log::LogStream(qi::LogLevel_Fatal, "", __FUNCTION__, 0, __VA_ARGS__).self()
48 # define _qiLogFatal(...) qi::log::LogStream(qi::LogLevel_Fatal, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()
52 # define _QI_FORMAT_ELEM(_, a, elem) % (elem)
54 # define _QI_LOG_FORMAT(Msg, ...) \
55 QI_CAT(_QI_LOG_FORMAT_HASARG_, _QI_LOG_ISEMPTY(__VA_ARGS__))(Msg, __VA_ARGS__)
57 #define _QI_LOG_FORMAT_HASARG_0(Msg, ...) \
58 boost::str(::qi::log::detail::getFormat(Msg) QI_VAARGS_APPLY(_QI_FORMAT_ELEM, _, __VA_ARGS__ ))
60 #define _QI_LOG_FORMAT_HASARG_1(Msg, ...) Msg
62 #define _QI_SECOND(a, ...) __VA_ARGS__
70 #ifndef _QI_LOG_VARIABLE_SUFFIX
71 # define _QI_LOG_VARIABLE_SUFFIX _x // dummy/default suffix
74 # define _QI_LOG_CATEGORY_GET() BOOST_PP_CAT(_qi_log_category, _QI_LOG_VARIABLE_SUFFIX)
76 #if defined(NO_QI_LOG_DETAILED_CONTEXT) || defined(NDEBUG)
77 # define _QI_LOG_MESSAGE(Type, Message) \
80 if (::qi::log::isVisible(_QI_LOG_CATEGORY_GET(), ::qi::Type)) \
81 ::qi::log::log(::qi::Type, \
82 _QI_LOG_CATEGORY_GET(), \
84 "", __FUNCTION__, 0); \
88 # define _QI_LOG_MESSAGE(Type, Message) \
91 if (::qi::log::isVisible(_QI_LOG_CATEGORY_GET(), ::qi::Type)) \
92 ::qi::log::log(::qi::Type, \
93 _QI_LOG_CATEGORY_GET(), \
95 __FILE__, __FUNCTION__, __LINE__); \
104 # define _QI_LOG_MESSAGE_STREAM(Type, TypeCased, ...) \
105 QI_CAT(_QI_LOG_MESSAGE_STREAM_HASCAT_, _QI_LOG_ISEMPTY( __VA_ARGS__))(Type, TypeCased, __VA_ARGS__)
108 #define _QI_LOG_MESSAGE_STREAM_HASCAT_1(Type, TypeCased, ...) \
109 ::qi::log::isVisible(_QI_LOG_CATEGORY_GET(), ::qi::Type) \
110 && BOOST_PP_CAT(_qiLog, TypeCased)(_QI_LOG_CATEGORY_GET())
114 #define _QI_LOG_MESSAGE_STREAM_HASCAT_0(...) QI_DELAY(_QI_LOG_MESSAGE_STREAM_HASCAT_0) ## _BOUNCE(__VA_ARGS__)
116 #define _QI_LOG_MESSAGE_STREAM_HASCAT_0(...) _QI_LOG_MESSAGE_STREAM_HASCAT_0_BOUNCE(__VA_ARGS__)
120 #define _QI_LOG_MESSAGE_STREAM_HASCAT_0_BOUNCE(Type, TypeCased, cat, ...) \
121 QI_CAT(_QI_LOG_MESSAGE_STREAM_HASCAT_HASFORMAT_, _QI_LOG_ISEMPTY( __VA_ARGS__))(Type, TypeCased, cat, __VA_ARGS__)
125 #define _QI_LOG_MESSAGE_STREAM_HASCAT_HASFORMAT_1(Type, TypeCased, cat, ...) \
126 BOOST_PP_CAT(_qiLog,TypeCased)(cat)
129 #define _QI_LOG_MESSAGE_STREAM_HASCAT_HASFORMAT_0(Type, TypeCased, cat, ...) \
130 BOOST_PP_CAT(_qiLog, TypeCased)(cat, _QI_LOG_FORMAT(__VA_ARGS__))
139 #define _WQI_IS_EMPTY_HELPER___ a,b
140 #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), _)))))
142 #define _QI_FIRST_ARG(a, ...) a
143 #define _QI_LOG_ISEMPTY(...) WQI_IS_EMPTY(QI_CAT_18(_, _QI_FIRST_ARG(__VA_ARGS__, 12)))
147 #define _QI_LOG_REVERSE 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0
148 #define _QI_LOG_REVERSEEMPTY 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1
149 #define _QI_LOG_ARGN(a, b, c, d, e, f, g, h, i, N, ...) N
150 #define _QI_LOG_NARG_(dummy, ...) _QI_LOG_ARGN(__VA_ARGS__)
151 #define _QI_LOG_NARG(...) _QI_LOG_NARG_(dummy, ##__VA_ARGS__, _QI_LOG_REVERSE)
152 #define _QI_LOG_ISEMPTY(...) _QI_LOG_NARG_(dummy, ##__VA_ARGS__, _QI_LOG_REVERSEEMPTY)
173 template <
typename T>
215 const std::string &rules);
221 return category && level <= category->
maxLevel;
225 class LogStream:
public std::stringstream, boost::noncopyable
230 const char *
function,
232 const char *category)
234 , _category(category)
237 , _function(function)
243 const char *
function,
248 , _categoryType(category)
250 , _function(function)
256 const char *
function,
258 const char *category,
259 const std::string& message)
261 , _category(category)
264 , _function(function)
273 qi::log::log(_logLevel, _category, this->str().c_str(), _file, _function, _line);
275 qi::log::log(_logLevel, _categoryType, this->str(), _file, _function, _line);
284 const char *_category;
287 const char *_function;
293 #endif // _QI_DETAIL_LOG_HXX_
LogStream(const qi::LogLevel level, const char *file, const char *function, const int line, const char *category)
void setLevel(SubscriberId sub, qi::LogLevel level)
LogStream(const qi::LogLevel level, const char *file, const char *function, const int line, CategoryType category)
LogLevel
Log level verbosity.
LogStream(const qi::LogLevel level, const char *file, const char *function, const int line, const char *category, const std::string &message)
unsigned int SubscriberId
Subscriber Identifier.
Category(const std::string &name)
bool operator<(bool, const NullStream &)
std::vector< qi::LogLevel > levels
std::vector< std::tuple< std::string, qi::LogLevel > > parseFilterRules(const std::string &rules)
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.
NullStream & operator<<(std::ostream &(*QI_UNUSED(f))(std::ostream &))
NullStream & operator<<(const T &QI_UNUSED(val))
boost::format getFormat(const std::string &s)
bool isVisible(CategoryType category, qi::LogLevel level)
Check if the given combination of category and level is enable.
#define QI_UNUSED(x)
This macro tags a parameter as unused.