libqi-api
2.8.7.4
|
Log functions with different levels of verbosity. More...
Namespaces | |
detail | |
env | |
Classes | |
class | LogStream |
class | ConsoleLogHandler |
Print colored logs to the console. More... | |
class | CsvLogHandler |
class | FileLogHandler |
class | HeadFileLogHandler |
Log the first length lines to a file. . More... | |
class | TailFileLogHandler |
Keeps at most 2 MiB of logs. . More... | |
Typedefs | |
using | CategoryType = detail::Category * |
Catergory Informations. More... | |
using | SubscriberId = unsigned int |
Subscriber Identifier. More... | |
typedef unsigned int | Subscriber |
using | 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 | 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... | |
Functions | |
bool | isVisible (CategoryType category, qi::LogLevel level) |
Check if the given combination of category and level is enable. More... | |
Handler | makeAndroidLogHandler () |
create a log handler which redirect logs to android log system. More... | |
Handler | makeJournaldLogHandler () |
Return a log handler, which forwards logs to systemd's journal. More... | |
void | 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 | destroy () |
Stop and flush the logging system. More... | |
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. More... | |
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. More... | |
const char * | logLevelToString (const qi::LogLevel verb, bool verbose=true) |
Convert log verbosity to a readable string. More... | |
qi::LogLevel | stringToLogLevel (const char *verb) |
Convert string to log verbosity. More... | |
void | setLogLevel (const qi::LogLevel lv, SubscriberId sub=0) |
Set log Level. More... | |
qi::LogLevel | logLevel (SubscriberId sub=0) |
Get log verbosity. More... | |
std::vector< std::string > | categories () |
Get the list of all categories. More... | |
CategoryType | addCategory (const std::string &name) |
Add/get a category. More... | |
void | enableCategory (const std::string &cat, SubscriberId sub=0) |
Set category to current verbosity level. Globbing is supported. More... | |
void | disableCategory (const std::string &cat, SubscriberId sub=0) |
Set category to silent log level. Globbing is supported. More... | |
bool | isVisible (const std::string &category, qi::LogLevel level) |
Check if the given combination of category and level is enable. More... | |
void | addFilters (const std::string &rules, SubscriberId sub=0) |
Parse and execute a set of verbosity rules. More... | |
void | addFilter (const std::string &cat, qi::LogLevel level, SubscriberId sub=0) |
Set per-subscriber category to level. Globbing is supported. More... | |
void | setContext (int ctx) |
Set log context verbosity. More... | |
int | context () |
Get log context. More... | |
void | setColor (LogColor color) |
Set log color. More... | |
LogColor | color () |
Get log color. More... | |
void | setSynchronousLog (bool sync) |
Enables or disables synchronous logs. More... | |
SubscriberId | addHandler (const std::string &name, qi::log::Handler fct, qi::LogLevel defaultLevel=LogLevel_Info) |
Add a log handler for this process' logs. More... | |
SubscriberId | addLogHandler (const std::string &name, qi::log::logFuncHandler fct, qi::LogLevel defaultLevel=LogLevel_Info) |
Add a log handler. More... | |
void | removeHandler (const std::string &name) |
Remove a log handler. More... | |
void | removeLogHandler (const std::string &name) |
Remove a log handler. More... | |
void | flush () |
Flush asynchronous logs. More... | |
void | setVerbosity (SubscriberId sub, const qi::log::LogLevel lv) |
void | setCategory (SubscriberId sub, const std::string &cat, qi::log::LogLevel level) |
Log functions with different levels of verbosity.
typedef detail::Category * qi::log::CategoryType |
using qi::log::Handler = typedef 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> |
using qi::log::logFuncHandler = typedef 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).
typedef unsigned int qi::log::Subscriber |
using qi::log::SubscriberId = typedef unsigned int |
CategoryType qi::log::addCategory | ( | const std::string & | name | ) |
Add/get a category.
name | Category to add/get. |
void qi::log::addFilter | ( | const std::string & | cat, |
qi::LogLevel | level, | ||
SubscriberId | sub = 0 |
||
) |
Set per-subscriber category to level. Globbing is supported.
cat | Category to set. |
level | Level to set to the category. |
sub | Log subscriber id. |
* .. code-block:: cpp * * 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 * *
void qi::log::addFilters | ( | const std::string & | rules, |
SubscriberId | sub = 0 |
||
) |
Parse and execute a set of verbosity rules.
rules | Colon separated of rules. Each rule can be:
|
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".
sub | Log subscriber id. |
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.
name | Name of the handler, useful to remove handler (prefer lowercase). |
fct | Boost delegate to log handler function. |
defaultLevel | default log verbosity. |
SubscriberId qi::log::addLogHandler | ( | const std::string & | name, |
qi::log::logFuncHandler | fct, | ||
qi::LogLevel | defaultLevel = LogLevel_Info |
||
) |
Add a log handler.
name | Name of the handler, useful to remove handler (prefer lowercase). |
fct | Boost delegate to log handler function. |
defaultLevel | default log verbosity. |
std::vector<std::string> qi::log::categories | ( | ) |
Get the list of all categories.
LogColor qi::log::color | ( | ) |
Get log color.
int qi::log::context | ( | ) |
Get log context.
void qi::log::destroy | ( | ) |
Stop and flush the logging system.
* Should be called in the main of program using atexit. For example: * * .. code-block:: cpp * * atexit(qi::log::destroy) * * This is useful only for asynchronous log. *
void qi::log::disableCategory | ( | const std::string & | cat, |
SubscriberId | sub = 0 |
||
) |
Set category to silent log level. Globbing is supported.
cat | Category to set to silence level. |
sub | Log subscriber id. |
void qi::log::enableCategory | ( | const std::string & | cat, |
SubscriberId | sub = 0 |
||
) |
Set category to current verbosity level. Globbing is supported.
cat | Category to set to current verbosity level. |
sub | Log subscriber id. |
void qi::log::flush | ( | ) |
Flush asynchronous logs.
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.
verb | Log verbosity level |
context | Display Context |
synchronous | Synchronous log |
|
inline |
bool qi::log::isVisible | ( | const std::string & | category, |
qi::LogLevel | level | ||
) |
Check if the given combination of category and level is enable.
category | Category to check. |
level | Level associate to category. |
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.
verb | The verbosity of the message. |
category | Log category (for filtering). |
msg | Log message. |
file | Filename from which this function was called (ex: FILE). |
fct | Function name from which this function was called (ex: FUNCTION). |
line | Line from which this function was called (ex: LINE). |
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.
verb | The verbosity of the message. |
category | Log category (for filtering). |
msg | Log message. |
file | Filename from which this function was called (ex: FILE). |
fct | Function name from which this function was called (ex: FUNCTION). |
line | Line from which this function was called (ex: LINE). |
qi::LogLevel qi::log::logLevel | ( | SubscriberId | sub = 0 | ) |
Get log verbosity.
sub | Log subscriber id. |
const char* qi::log::logLevelToString | ( | const qi::LogLevel | verb, |
bool | verbose = true |
||
) |
Convert log verbosity to a readable string.
verb | Verbosity value. |
verbose | Enable verbose conversion. |
Handler qi::log::makeAndroidLogHandler | ( | ) |
create a log handler which redirect logs to android log system.
Limitations: timestamps, file name, function name and line number are discarded.Handler qi::log::makeJournaldLogHandler | ( | ) |
Return a log handler, which forwards logs to systemd's journal.
The following journal fields are added:
The returned handler is not thread-safe, which is fine: libqi does not call its log handlers concurrently.
void qi::log::removeHandler | ( | const std::string & | name | ) |
Remove a log handler.
name | Name of the handler. |
void qi::log::removeLogHandler | ( | const std::string & | name | ) |
Remove a log handler.
name | Name of the handler. |
|
inline |
void qi::log::setColor | ( | LogColor | color | ) |
Set log color.
color | Log color value. |
void qi::log::setContext | ( | int | ctx | ) |
Set log context verbosity.
Show context logs, it's a bit field (add the values below).
ctx | Value to set context. |
Context values possible:
Can be set with env var QI_LOG_CONTEXT
void qi::log::setLogLevel | ( | const qi::LogLevel | lv, |
SubscriberId | sub = 0 |
||
) |
Set log Level.
lv | Default verbosity level shown in the logs. |
sub | Log subscriber id. |
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):
Can be set with env var QI_LOG_LEVEL.
If you don't want any log use silent mode.
void qi::log::setSynchronousLog | ( | bool | sync | ) |
Enables or disables synchronous logs.
sync | Value to set or unset synchronous. |
When setting to async, this function must be called after main has started.
|
inline |
qi::LogLevel qi::log::stringToLogLevel | ( | const char * | verb | ) |
Convert string to log verbosity.
verb | debug, verbose, info, warning, error, fatal, silent |