Global Namespaces
namespace qi::log
Functions (namespace qi::log)
Global Macros
qi::log provides logging facilities. It allows one to log in different categories with different levels.
The user can choose which categories they want to see and at which level. It is possible to add handlers to process the log, broadcast them on the network, save them in a file, etc.
Logs are not modified when printed or transmitted.
That means that if the source file is UTF-8 AND the compiler considers your string literals as UTF-8 AND the output handles UTF-8 then all logs are printed the same.
Warning
On Windows, the compiler (VS-2013) won’t necessarily interpret string literals as UTF-8. Most of the time with special characters, the behavior is undefined.
#include <qi/log.hpp>
qiLogCategory("myprogram.mymodule");
int main()
{
qiLogInfo() << "Hello world";
// this variant is slower than the one above
qiLogError("this.goes.in.another.category") << "Goodbye world";
return 0;
}
Warning
Log calls are lazily evaluated. When you put a function call in your log statements, the function will not be called if the log is disabled (at runtime or compilation-time).
int i = 0;
int f() { ++i; return 0; }
void g() {
qiLogVerbose() << f(); // f() may not be called!
}
qiLogCategory(Cat)
¶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.
{
qiLogCategory(my.category);
qiLogInfoF("1 + 1 is %s", 1+1);
qiLogInfo() << "1 + 1 is " << 1+1;
}
qiLogDebug(...)
¶Log in debug mode. Not compiled on release and not shown by default. Use as follow:
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.
qiLogDebugF(Msg, ...)
¶qiLogVerbose(...)
¶Log in verbose mode. This level is not shown by default.
qiLogVerboseF(Msg, ...)
¶qiLogInfo(...)
¶Log in info mode.
qiLogInfoF(Msg, ...)
¶qiLogWarning(...)
¶Log in warning mode.
qiLogWarningF(Msg, ...)
¶qiLogError(...)
¶Log in error mode.
qiLogErrorF(Msg, ...)
¶qiLogFatal(...)
¶Log in fatal mode.
qiLogFatalF(Msg, ...)
¶qi::LogColor
¶Brief: Logs color mode.
Name | Brief |
---|---|
LogColor_Never |
Never show color. |
LogColor_Auto |
Auto color. |
LogColor_Always |
Always show color. |
qi::LogContextAttr
¶Brief: Logs context attribute.
Name | Value | Brief |
---|---|---|
LogContextAttr_None |
0 | No context. |
LogContextAttr_Verbosity |
1 | Show logs level. |
LogContextAttr_ShortVerbosity |
2 | Show short logs level. |
LogContextAttr_SystemDate |
4 | Show qi::SystemClock dates. |
LogContextAttr_Tid |
8 | Show threads id. |
LogContextAttr_Category |
16 | Show categories. |
LogContextAttr_File |
32 | Show logs files. |
LogContextAttr_Function |
64 | Show functions name. |
LogContextAttr_Return |
128 | Print an end line between contexts and logs. |
LogContextAttr_Date |
256 | Show qi::Clock dates. |
qi::LogLevel
¶Brief: Log level verbosity.
Name | Value | Brief |
---|---|---|
LogLevel_Silent |
0 | silent log level |
LogLevel_Fatal |
fatal log level | |
LogLevel_Error |
error log level | |
LogLevel_Warning |
warning log level | |
LogLevel_Info |
info log level | |
LogLevel_Verbose |
verbose log level | |
LogLevel_Debug |
debug log level |
qi::log::
addCategory
(const std::string& name)¶Brief: Add/get a category.
Parameters: |
|
---|---|
Returns: | CategoryType structure. |
qi::log::
addFilter
(const std::string& cat, qi::LogLevel level, SubscriberId sub = 0)¶Brief: Set per-subscriber category to level. Globbing is supported.
Parameters: |
|
---|
addFilter("internal.*", silent);
One can also set a filtering rule in QI_LOG_FILTERS environment variable. syntax is colon-separated list of rules of the form (+|-)CAT or CAT=level. For example, -internal.*:file=verbose
qi::log::
addFilters
(const std::string& rules, SubscriberId sub = 0)¶Brief: Parse and execute a set of verbosity rules.
Parameters: |
|
---|
Each category can include a ‘*’ for globbing. Can be set with env var QI_LOG_FILTERS. For instance ‘qi.*=debug:-qi.foo:+qi.foo.bar’ stands for “all qi.* logs in debug, remove all qi.foo logs except qi.foo.bar”.
qi::log::
addHandler
(const std::string& name, qi::log::Handler fct, qi::LogLevel defaultLevel = LogLevel_Info)¶Brief: Add a log handler for this process’ logs.
Parameters: |
|
---|---|
Returns: | New log subscriber id added. |
qi::log::
categories
()¶Brief: Get the list of all categories.
Returns: | The list of existing categories |
---|
qi::log::
color
()¶Brief: Get log color.
Returns: | Returns LogColor enum. |
---|
qi::log::
context
()¶Brief: Get log context.
Returns: | Returns the level of context verbosity. |
---|
qi::log::
destroy
()¶Should be called in the main of program using atexit. For example:
atexit(qi::log::destroy)
This is useful only for asynchronous log.
qi::log::
disableCategory
(const std::string& cat, SubscriberId sub = 0)¶Brief: Set category to silent log level. Globbing is supported.
Parameters: |
|
---|
qi::log::
enableCategory
(const std::string& cat, SubscriberId sub = 0)¶Brief: Set category to current verbosity level. Globbing is supported.
Parameters: |
|
---|
qi::log::
flush
()¶Flush asynchronous logs.
qi::log::
init
(qi::LogLevel verb = qi::LogLevel_Info, qi::LogContext context = qi::LogContextAttr_ShortVerbosity|qi::LogContextAttr_Tid|qi::LogContextAttr_Category, bool synchronous = true)¶Brief: Initialization of the logging system (could be avoided)
Parameters: |
|
---|
qi::log::
isVisible
(CategoryType category, qi::LogLevel level)¶Brief: Check if the given combination of category and level is enable.
Parameters: |
|
---|---|
Returns: | true if given combination of category and level is enabled. |
qi::log::
isVisible
(const std::string& category, qi::LogLevel level)¶Brief: Check if the given combination of category and level is enable.
Parameters: |
|
---|---|
Returns: | true if given combination of category and level is enabled. |
qi::log::
log
(const qi::LogLevel verb, CategoryType category, const std::string& msg, const char* file = "", const char* fct = "", const int line = 0)¶Brief: Log function. You should call qiLog* macros instead.
Parameters: |
|
---|
qi::log::
log
(const qi::LogLevel verb, const char* category, const char* msg, const char* file = "", const char* fct = "", const int line = 0)¶Brief: Log function. You should call qiLog* macros instead.
Parameters: |
|
---|
qi::log::
logLevel
(SubscriberId sub = 0)¶Brief: Get log verbosity.
Parameters: |
|
---|---|
Returns: | Maximal verbosity displayed. |
qi::log::
logLevelToString
(const qi::LogLevel verb, bool verbose = true)¶Brief: Convert log verbosity to a readable string.
Parameters: |
|
---|---|
Returns: | Returns a string matching the log level verbosity. |
qi::log::
removeHandler
(const std::string& name)¶Brief: Remove a log handler.
Parameters: |
|
---|
qi::log::
setColor
(LogColor color)¶Brief: Set log color.
Parameters: |
|
---|
qi::log::
setContext
(int ctx)¶Brief: Set log context verbosity.
Parameters: |
|
---|
Show context logs, it’s a bit field (add the values below).
Context values possible: 1 : Verbosity2 : ShortVerbosity4 : Date8 : ThreadId16 : Category32 : File64 : Function128: EndOfLine some useful values for context are:26 : (verb+threadId+cat)30 : (verb+threadId+date+cat)126: (verb+threadId+date+cat+file+fun)254: (verb+threadId+date+cat+file+fun+eol)
Can be set with env var QI_LOG_CONTEXT
qi::log::
setSynchronousLog
(bool sync)¶Brief: Enables or disables synchronous logs.
Parameters: |
|
---|
When setting to async, this function must be called after main has started.
qi::log::
setLogLevel
(const qi::LogLevel lv, SubscriberId sub = 0)¶Brief: Set log Level.
Parameters: |
|
---|
Levels set by this function is a default value, overriden by all addFilter() and addFilters() calls.
Change the log minimum level: [0-6] (default:4): 0: silent1: fatal2: error3: warning4: info5: verbose6: debug
Can be set with env var QI_LOG_LEVEL.
If you don’t want any log use silent mode.
qi::log::
stringToLogLevel
(const char* verb)¶Brief: Convert string to log verbosity.
Parameters: |
|
---|---|
Returns: | Log level verbosity |
qi::log::
setVerbosity
(SubscriberId sub, const qi::log::LogLevel lv)¶Deprecatedsince 1.22. Use qi::log::setLogLevel(const qi::LogLevel, SubscriberId)
qi::log::
setVerbosity
(SubscriberId sub, const qi::log::LogLevel lv)Deprecatedsince 1.22. Use qi::log::setLogLevel(const qi::LogLevel, SubscriberId)
qi::log::
setVerbosity
(SubscriberId sub, const qi::log::LogLevel lv)Deprecatedsince 1.22. Use qi::log::setLogLevel(const qi::LogLevel, SubscriberId)
qi::log::
setCategory
(SubscriberId sub, const std::string& cat, qi::log::LogLevel level)¶Deprecatedsince 1.22. Use qi::log::addFilter(const std::string&, qi::LogLevel, SubscriberId)
qi::log::
setCategory
(SubscriberId sub, const std::string& cat, qi::log::LogLevel level)Deprecatedsince 1.22. Use qi::log::addFilter(const std::string&, qi::LogLevel, SubscriberId)
qi::log::
verbosity
(SubscriberId)¶