libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
log.hpp File Reference

Convenient log macro. More...

#include <string>
#include <sstream>
#include <cstdarg>
#include <cstdio>
#include <boost/format.hpp>
#include <boost/function/function_fwd.hpp>
#include <qi/os.hpp>
#include <stdexcept>
#include <boost/exception/exception.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <ka/macroregular.hpp>
#include <ka/typetraits.hpp>
#include <ka/utility.hpp>
#include <qi/detail/warn_push_ignore_deprecated.hpp>
#include <qi/detail/warn_pop_ignore_deprecated.hpp>
#include <qi/detail/log.hxx>

Go to the source code of this file.

Classes

struct  qi::ExceptionLogError< O, S >
 

Namespaces

 qi
 Deprecated in 2.5. Use int8_t from <cstdint>.
 
 qi::log
 Log functions with different levels of verbosity.
 
 qi::log::detail
 
 qi::log::env
 
 qi::log::env::QI_DEFAULT_LOGHANDLER
 
 qi::log::env::QI_DEFAULT_LOGHANDLER::value
 

Macros

#define _QI_LOG_HPP_
 
#define qiLogCategory(Cat)
 
#define qiLogDebug(...)   _QI_LOG_MESSAGE_STREAM(LogLevel_Debug, Debug , __VA_ARGS__)
 
#define qiLogDebugF(Msg,...)   _QI_LOG_MESSAGE(LogLevel_Debug, _QI_LOG_FORMAT(Msg, __VA_ARGS__))
 
#define qiLogVerbose(...)   _QI_LOG_MESSAGE_STREAM(LogLevel_Verbose, Verbose, __VA_ARGS__)
 Log in verbose mode. This level is not shown by default. More...
 
#define qiLogVerboseF(Msg,...)   _QI_LOG_MESSAGE(LogLevel_Verbose, _QI_LOG_FORMAT(Msg, __VA_ARGS__))
 
#define qiLogInfo(...)   _QI_LOG_MESSAGE_STREAM(LogLevel_Info, Info, __VA_ARGS__)
 Log in info mode. More...
 
#define qiLogInfoF(Msg,...)   _QI_LOG_MESSAGE(LogLevel_Info, _QI_LOG_FORMAT(Msg, __VA_ARGS__))
 
#define qiLogWarning(...)   _QI_LOG_MESSAGE_STREAM(LogLevel_Warning, Warning, __VA_ARGS__)
 Log in warning mode. More...
 
#define qiLogWarningF(Msg,...)   _QI_LOG_MESSAGE(LogLevel_Warning, _QI_LOG_FORMAT(Msg, __VA_ARGS__))
 
#define qiLogError(...)   _QI_LOG_MESSAGE_STREAM(LogLevel_Error, Error, __VA_ARGS__)
 Log in error mode. More...
 
#define qiLogErrorF(Msg,...)   _QI_LOG_MESSAGE(LogLevel_Error, _QI_LOG_FORMAT(Msg, __VA_ARGS__))
 
#define qiLogFatal(...)   _QI_LOG_MESSAGE_STREAM(LogLevel_Fatal, Fatal, __VA_ARGS__)
 Log in fatal mode. More...
 
#define qiLogFatalF(Msg,...)   _QI_LOG_MESSAGE(LogLevel_Fatal, _QI_LOG_FORMAT(Msg, __VA_ARGS__))
 

Typedefs

using qi::LogContext = int
 Logs context attribute value. More...
 
using qi::log::SubscriberId = unsigned int
 Subscriber Identifier. More...
 
typedef unsigned int qi::log::Subscriber
 
using qi::log::logFuncHandler = boost::function7< void, const qi::LogLevel, const qi::os::timeval, const char *, const char *, const char *, const char *, int >
 Boost delegate to log function (verbosity lv, date of log, category, message, file, function, line). More...
 
using qi::log::Handler = boost::function8< void, const qi::LogLevel, const qi::Clock::time_point, const qi::SystemClock::time_point, const char *, const char *, const char *, const char *, int >
 Boost delegate to log function (verbosity lv, dates of log, category, message, file, function, line). More...
 

Enumerations

enum  qi::LogLevel {
  qi::LogLevel_Silent = 0, qi::LogLevel_Fatal, qi::LogLevel_Error, qi::LogLevel_Warning,
  qi::LogLevel_Info, qi::LogLevel_Verbose, qi::LogLevel_Debug
}
 Log level verbosity. More...
 
enum  qi::LogColor { qi::LogColor_Never, qi::LogColor_Auto, qi::LogColor_Always }
 Logs color mode. More...
 
enum  qi::LogContextAttr {
  qi::LogContextAttr_None = 0, qi::LogContextAttr_Verbosity = 1 << 0, qi::LogContextAttr_ShortVerbosity = 1 << 1, qi::LogContextAttr_SystemDate = 1 << 2,
  qi::LogContextAttr_Tid = 1 << 3, qi::LogContextAttr_Category = 1 << 4, qi::LogContextAttr_File = 1 << 5, qi::LogContextAttr_Function = 1 << 6,
  qi::LogContextAttr_Return = 1 << 7, qi::LogContextAttr_Date = 1 << 8
}
 Logs context attribute. More...
 

Functions

void qi::log::init (qi::LogLevel verb=qi::LogLevel_Info, qi::LogContext context=qi::LogContextAttr_ShortVerbosity|qi::LogContextAttr_Tid|qi::LogContextAttr_Category, bool synchronous=true)
 Initialization of the logging system Creates and registers the default log handler according to QI_DEFAULT_LOGHANDLER environment variable and compilation flags WITH_SYSTEMD, ANDROID and BOOST_OS_WINDOWS. More...
 
void qi::log::destroy ()
 Stop and flush the logging system. More...
 
void qi::log::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. More...
 
void qi::log::log (const qi::LogLevel verb, CategoryType category, const std::string &msg, const char *file="", const char *fct="", const int line=0)
 Log function. You should call qiLog* macros instead. More...
 
const char * qi::log::logLevelToString (const qi::LogLevel verb, bool verbose=true)
 Convert log verbosity to a readable string. More...
 
qi::LogLevel qi::log::stringToLogLevel (const char *verb)
 Convert string to log verbosity. More...
 
void qi::log::setLogLevel (const qi::LogLevel lv, SubscriberId sub=0)
 Set log Level. More...
 
qi::LogLevel qi::log::logLevel (SubscriberId sub=0)
 Get log verbosity. More...
 
std::vector< std::string > qi::log::categories ()
 Get the list of all categories. More...
 
CategoryType qi::log::addCategory (const std::string &name)
 Add/get a category. More...
 
void qi::log::enableCategory (const std::string &cat, SubscriberId sub=0)
 Set category to current verbosity level. Globbing is supported. More...
 
void qi::log::disableCategory (const std::string &cat, SubscriberId sub=0)
 Set category to silent log level. Globbing is supported. More...
 
bool qi::log::isVisible (CategoryType category, qi::LogLevel level)
 Check if the given combination of category and level is enable. More...
 
bool qi::log::isVisible (const std::string &category, qi::LogLevel level)
 Check if the given combination of category and level is enable. More...
 
void qi::log::addFilters (const std::string &rules, SubscriberId sub=0)
 Parse and execute a set of verbosity rules. More...
 
void qi::log::addFilter (const std::string &cat, qi::LogLevel level, SubscriberId sub=0)
 Set per-subscriber category to level. Globbing is supported. More...
 
void qi::log::setContext (int ctx)
 Set log context verbosity. More...
 
int qi::log::context ()
 Get log context. More...
 
void qi::log::setColor (LogColor color)
 Set log color. More...
 
LogColor qi::log::color ()
 Get log color. More...
 
void qi::log::setSynchronousLog (bool sync)
 Enables or disables synchronous logs. More...
 
SubscriberId qi::log::addHandler (const std::string &name, qi::log::Handler fct, qi::LogLevel defaultLevel=LogLevel_Info)
 Add a log handler for this process' logs. More...
 
SubscriberId qi::log::addLogHandler (const std::string &name, qi::log::logFuncHandler fct, qi::LogLevel defaultLevel=LogLevel_Info)
 Add a log handler. More...
 
void qi::log::removeHandler (const std::string &name)
 Remove a log handler. More...
 
void qi::log::removeLogHandler (const std::string &name)
 Remove a log handler. More...
 
void qi::log::flush ()
 Flush asynchronous logs. More...
 
void qi::log::setVerbosity (SubscriberId sub, const qi::log::LogLevel lv)
 
void qi::log::setCategory (SubscriberId sub, const std::string &cat, qi::log::LogLevel level)
 
template<typename O , typename S >
ExceptionLogError< ka::Decay
< O >, ka::Decay< S > > 
qi::exceptionLogError (S &&category, O &&prefix)
 

Variables

char const *const qi::log::env::QI_DEFAULT_LOGHANDLER::name
 
char const *const qi::log::env::QI_DEFAULT_LOGHANDLER::value::none
 
char const *const qi::log::env::QI_DEFAULT_LOGHANDLER::value::stdOut
 
char const *const qi::log::env::QI_DEFAULT_LOGHANDLER::value::logger
 
char const *const qi::log::env::QI_DEFAULT_LOGHANDLER::value::debugger
 

Detailed Description

Convenient log macro.

Definition in file log.hpp.

Macro Definition Documentation

#define _QI_LOG_HPP_

Definition at line 16 of file log.hpp.

#define qiLogCategory (   Cat)
Value:
::qi::log::addCategory(Cat)
CategoryType addCategory(const std::string &name)
Add/get a category.
void log(const qi::LogLevel verb, CategoryType category, const std::string &msg, const char *file="", const char *fct="", const int line=0)
Log function. You should call qiLog* macros instead.
#define _QI_LOG_CATEGORY_GET()
Definition: log.hxx:74
detail::Category * CategoryType
Catergory Informations.
Definition: log.hxx:224
#define QI_ATTR_UNUSED
This macro tags a attribute as unused.
Definition: macro.hpp:262
* Add default category for the current scope.
* Each log has a category defined by the call to qiLogCategory()
* found in scope. So you must call qiLogCategory() at least once, for
* instance at the beginning of your source file or function.
*
* .. code-block:: cpp
*
*     {
*       qiLogCategory(my.category);
*       qiLogInfoF("1 + 1 is %s", 1+1);
*       qiLogInfo() << "1 + 1 is " << 1+1;
*     }
* 

Definition at line 53 of file log.hpp.

#define qiLogDebug (   ...)    _QI_LOG_MESSAGE_STREAM(LogLevel_Debug, Debug , __VA_ARGS__)
* Log in debug mode. Not compiled on release and not shown by default.
* Use as follow:
*
* .. code-block:: cpp
*
*     qiLogDebug("foo.bar", "my foo is %d bar", 42);
*     // or
*     qiLogDebug("foo.bar") << "my foo is " << 42 << "bar";
*
* If you don't want to see any log, use silent log level.
* 

Definition at line 76 of file log.hpp.

#define qiLogDebugF (   Msg,
  ... 
)    _QI_LOG_MESSAGE(LogLevel_Debug, _QI_LOG_FORMAT(Msg, __VA_ARGS__))

Definition at line 77 of file log.hpp.

#define qiLogError (   ...)    _QI_LOG_MESSAGE_STREAM(LogLevel_Error, Error, __VA_ARGS__)

Log in error mode.

Definition at line 120 of file log.hpp.

#define qiLogErrorF (   Msg,
  ... 
)    _QI_LOG_MESSAGE(LogLevel_Error, _QI_LOG_FORMAT(Msg, __VA_ARGS__))

Definition at line 121 of file log.hpp.

#define qiLogFatal (   ...)    _QI_LOG_MESSAGE_STREAM(LogLevel_Fatal, Fatal, __VA_ARGS__)

Log in fatal mode.

Definition at line 131 of file log.hpp.

#define qiLogFatalF (   Msg,
  ... 
)    _QI_LOG_MESSAGE(LogLevel_Fatal, _QI_LOG_FORMAT(Msg, __VA_ARGS__))

Definition at line 132 of file log.hpp.

#define qiLogInfo (   ...)    _QI_LOG_MESSAGE_STREAM(LogLevel_Info, Info, __VA_ARGS__)

Log in info mode.

Definition at line 98 of file log.hpp.

#define qiLogInfoF (   Msg,
  ... 
)    _QI_LOG_MESSAGE(LogLevel_Info, _QI_LOG_FORMAT(Msg, __VA_ARGS__))

Definition at line 99 of file log.hpp.

#define qiLogVerbose (   ...)    _QI_LOG_MESSAGE_STREAM(LogLevel_Verbose, Verbose, __VA_ARGS__)

Log in verbose mode. This level is not shown by default.

Definition at line 87 of file log.hpp.

#define qiLogVerboseF (   Msg,
  ... 
)    _QI_LOG_MESSAGE(LogLevel_Verbose, _QI_LOG_FORMAT(Msg, __VA_ARGS__))

Definition at line 88 of file log.hpp.

#define qiLogWarning (   ...)    _QI_LOG_MESSAGE_STREAM(LogLevel_Warning, Warning, __VA_ARGS__)

Log in warning mode.

Definition at line 109 of file log.hpp.

#define qiLogWarningF (   Msg,
  ... 
)    _QI_LOG_MESSAGE(LogLevel_Warning, _QI_LOG_FORMAT(Msg, __VA_ARGS__))

Definition at line 110 of file log.hpp.