libqi  1.14.5
Classes | Namespaces | Defines | Typedefs | Enumerations | Functions
qi::log

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.

Detailed Description

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";
  }
Warning:
You should call qi::log::init at the start of your program and register a handler when the program exit to destroy the logger.

Define Documentation

#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";
Examples:
log_example.cpp.

Definition at line 33 of file log.hpp.

#define qiLogError (   ...)    qi::log::LogStream(qi::log::error, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()

Log in error mode.

Examples:
log_example.cpp.

Definition at line 65 of file log.hpp.

#define qiLogFatal (   ...)    qi::log::LogStream(qi::log::fatal, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()

Log in fatal mode.

Examples:
log_example.cpp.

Definition at line 73 of file log.hpp.

#define qiLogInfo (   ...)    qi::log::LogStream(qi::log::info, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()

Log in info mode.

Examples:
log_example.cpp.

Definition at line 49 of file log.hpp.

#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.

Examples:
log_example.cpp.

Definition at line 41 of file log.hpp.

#define qiLogWarning (   ...)    qi::log::LogStream(qi::log::warning, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__).self()

Log in warning mode.

Examples:
log_example.cpp.

Definition at line 57 of file log.hpp.


Enumeration Type Documentation

Log level verbosity.

Enumerator:
silent 

silent log level

fatal 

fatal log level

error 

error log level

warning 

warning log level

info 

info log level

verbose 

verbose log level

debug 

debug log level

Definition at line 119 of file log.hpp.


Function Documentation

void qi::log::addLogHandler ( const std::string &  name,
qi::log::logFuncHandler  fct 
)

Add log handler.

Parameters:
fctBoost delegate to log handler function.
namename of the handler, this is the one used to remove handler (prefer lowcase).

Get log context.

Returns:
true if active, false otherwise.
void qi::log::init ( qi::log::LogLevel  verb = qi::log::info,
int  ctx = 0,
bool  synchronous = true 
)

init the logging system (could be avoided)

Parameters:
verbLog verbosity
ctxDisplay Context
synchronousSynchronous 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.

Parameters:
verb{ debug = 6, verbose = 5, info = 4, warning = 3, error = 2, fatal = 1, silent = 0 }
categoryLog category.
msgLog message.
file__FILE__
fct__FUNCTION__
line__LINE__
const char * qi::log::logLevelToString ( const qi::log::LogLevel  verb)

Convert log verbosity to char*.

Parameters:
verb{ debug = 6, verbose=5, info = 4, warning = 3, error = 2, fatal = 1, silent = 0 }
Returns:
one of [SILENT], [FATAL], [ERROR], [WARN ], [INFO ], [VERB ], [DEBUG]
void qi::log::removeLogHandler ( const std::string &  name)

remove log handler.

Parameters:
namename of the handler.
Examples:
log_example.cpp.
void qi::log::setContext ( int  ctx)

Set log context.Display log context (line, function, file).

Parameters:
ctxValue to set context.
  • 0: none
  • 1: categories
  • 2: date
  • 3: file+line
  • 4: date+categories
  • 5: date+line+file
  • 6: categories+line+file
  • 7: all (date+categories+line+file+function)
Examples:
log_example.cpp.
void qi::log::setSynchronousLog ( bool  sync)

Set synchronous logs.

Parameters:
syncValue to set context.
Examples:
log_example.cpp.

Set log verbosity.If you don't want any log use silent mode.

Parameters:
lvmaximal verbosity shown
Examples:
log_example.cpp.
const qi::log::LogLevel qi::log::stringToLogLevel ( const char *  verb)

Convert string to log verbosity.

Parameters:
verbdebug, verbose, info, warning, error, fatal, silent
Returns:
Log level verbosity

Get log verbosity.

Returns:
Maximal verbosity display.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines