libqi
1.14.5
|
logging facilities (with rt support)
See qi::log Developer Guide for a global overview of the logging system.
More...
Classes | |
class | qi::log::ConsoleLogHandler |
Print colored logs to the consoleColor will be enable only when the output is a tty. More... | |
class | qi::log::FileLogHandler |
log to file handler More... | |
class | qi::log::HeadFileLogHandler |
Log the length first lines to file. More... | |
class | qi::log::TailFileLogHandler |
Log the length first lines to file. More... | |
class | qi::log::LogStream |
Each log macro create a LogStream object. More... | |
Namespaces | |
namespace | qi::log |
Log functions. | |
Defines | |
#define | qiLogDebug(...) qi::log::LogStream(qi::log::debug, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
#define | qiLogVerbose(...) qi::log::LogStream(qi::log::verbose, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
#define | qiLogInfo(...) qi::log::LogStream(qi::log::info, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
#define | qiLogWarning(...) qi::log::LogStream(qi::log::warning, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
#define | qiLogError(...) qi::log::LogStream(qi::log::error, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
#define | qiLogFatal(...) qi::log::LogStream(qi::log::fatal, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
Typedefs | |
typedef boost::function7< void, const qi::log::LogLevel, const qi::os::timeval, const char *, const char *, const char *, const char *, int > | qi::log::logFuncHandler |
Boost delegate to log function (verbosity lv, date of log, category, message, file, function, line). e.g. | |
Enumerations | |
enum | qi::log::LogLevel { qi::log::silent = 0, qi::log::fatal, qi::log::error, qi::log::warning, qi::log::info, qi::log::verbose, qi::log::debug } |
Log level verbosity. More... | |
Functions | |
QI_API void | qi::log::init (qi::log::LogLevel verb=qi::log::info, int ctx=0, bool synchronous=true) |
init the logging system (could be avoided) | |
QI_API void | qi::log::destroy () |
stop and flush the logging systemshould be called in the main of program using atexit. for example: atexit(qi::log::destroy) This is useful only for asynchronous log. | |
QI_API void | qi::log::log (const qi::log::LogLevel verb, const char *category, const char *msg, const char *file="", const char *fct="", const int line=0) |
Log functionYou should call qiLog* macro. | |
QI_API const char * | qi::log::logLevelToString (const qi::log::LogLevel verb) |
Convert log verbosity to char*. | |
QI_API qi::log::LogLevel | qi::log::stringToLogLevel (const char *verb) |
Convert string to log verbosity. | |
QI_API void | qi::log::setVerbosity (const qi::log::LogLevel lv) |
Set log verbosity.If you don't want any log use silent mode. | |
QI_API qi::log::LogLevel | qi::log::verbosity () |
Get log verbosity. | |
QI_API void | qi::log::setContext (int ctx) |
Set log context.Display log context (line, function, file). | |
QI_API int | qi::log::context () |
Get log context. | |
QI_API void | qi::log::setSynchronousLog (bool sync) |
Set synchronous logs. | |
QI_API void | qi::log::addLogHandler (const std::string &name, qi::log::logFuncHandler fct) |
Add log handler. | |
QI_API void | qi::log::removeLogHandler (const std::string &name) |
remove log handler. | |
QI_API void | qi::log::flush () |
flush asynchronous log. |
logging facilities (with rt support)
See qi::log Developer Guide for a global overview of the logging system.
How to use log:
#include <cstdlib> //for atexit #include <qi/log.hpp> void main() { // first init the log system qi::log::init(); atexit(qi::log::destroy); // c syntax qiLogInfo("foo.bar", "%s kick %s" , "foo", "bar"); qiLogInfo("foo.bar", "%s punch %s", "bar", "foo"); qiLogWarning("pif.paf", "pif kiss paf %d time", 42); // c++ syntax qiLogInfo("tic.tac") << "tic, " << "tac " << 42 << " times"; qiLogVerbose("foo.bar") << "bar punch " << "foo"; }
#define qiLogDebug | ( | ... | ) | qi::log::LogStream(qi::log::debug, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
Log in debug mode. Not compile on release. use as follow:
qiLogDebug("foo.bar", "my foo is %d bar", 42); or qiLogDebug("foo.bar") << "my foo is " << 42 << "bar";
#define qiLogError | ( | ... | ) | qi::log::LogStream(qi::log::error, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
#define qiLogFatal | ( | ... | ) | qi::log::LogStream(qi::log::fatal, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
#define qiLogInfo | ( | ... | ) | qi::log::LogStream(qi::log::info, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
#define qiLogVerbose | ( | ... | ) | qi::log::LogStream(qi::log::verbose, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
Log in verbose mode. This mode isn't show by default but always compile.
#define qiLogWarning | ( | ... | ) | qi::log::LogStream(qi::log::warning, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self() |
enum qi::log::LogLevel |
void qi::log::addLogHandler | ( | const std::string & | name, |
qi::log::logFuncHandler | fct | ||
) |
Add log handler.
fct | Boost delegate to log handler function. |
name | name of the handler, this is the one used to remove handler (prefer lowcase). |
int qi::log::context | ( | ) |
Get log context.
void qi::log::init | ( | qi::log::LogLevel | verb = qi::log::info , |
int | ctx = 0 , |
||
bool | synchronous = true |
||
) |
init the logging system (could be avoided)
verb | Log verbosity |
ctx | Display Context |
synchronous | Synchronous log? |
void qi::log::log | ( | const qi::log::LogLevel | verb, |
const char * | category, | ||
const char * | msg, | ||
const char * | file = "" , |
||
const char * | fct = "" , |
||
const int | line = 0 |
||
) |
Log functionYou should call qiLog* macro.
verb | { debug = 6, verbose = 5, info = 4, warning = 3, error = 2, fatal = 1, silent = 0 } |
category | Log category. |
msg | Log message. |
file | __FILE__ |
fct | __FUNCTION__ |
line | __LINE__ |
const char * qi::log::logLevelToString | ( | const qi::log::LogLevel | verb | ) |
Convert log verbosity to char*.
verb | { debug = 6, verbose=5, info = 4, warning = 3, error = 2, fatal = 1, silent = 0 } |
void qi::log::removeLogHandler | ( | const std::string & | name | ) |
void qi::log::setContext | ( | int | ctx | ) |
Set log context.Display log context (line, function, file).
ctx | Value to set context.
|
void qi::log::setSynchronousLog | ( | bool | sync | ) |
void qi::log::setVerbosity | ( | const qi::log::LogLevel | lv | ) |
Set log verbosity.If you don't want any log use silent mode.
lv | maximal verbosity shown |
const qi::log::LogLevel qi::log::stringToLogLevel | ( | const char * | verb | ) |
Convert string to log verbosity.
verb | debug, verbose, info, warning, error, fatal, silent |
Get log verbosity.