libqi-api  2.0.6.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Namespaces | Classes | Typedefs | Functions | Variables
qi::log Namespace Reference

Log functions with different levels of verbosity. More...

Namespaces

namespace  detail

Classes

class  LogStream
 Each log macro creates a LogStream object. More...
class  ConsoleLogHandler
 Print colored logs to the console. More...
class  FileLogHandler
 Log messages to a file. More...
class  HeadFileLogHandler
 Log the first length lines to a file. More...
class  TailFileLogHandler
 Keeps at most 2 MiB of logs. More...

Typedefs

typedef detail::Category * CategoryType
typedef unsigned int SubscriberId
typedef boost::function7< void,
const qi::LogLevel, const
qi::os::timeval, const char
*, const char *, const char
*, const char *, int > 
logFuncHandler
 Boost delegate to log function (verbosity lv, date of log, category, message, file, function, line).

Functions

void init (qi::LogLevel verb=qi::LogLevel_Info, qi::LogContext context=qi::LogContextAttr_ShortVerbosity|qi::LogContextAttr_Tid|qi::LogContextAttr_Category, bool synchronous=true)
 init the logging system (could be avoided)
void destroy ()
 Stop and flush the logging system.
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.
void log (const qi::LogLevel verb, CategoryType category, const std::string &msg, const char *file="", const char *fct="", const int line=0)
const char * logLevelToString (const qi::LogLevel verb, bool verbose=true)
qi::LogLevel stringToLogLevel (const char *verb)
 Convert string to log verbosity.
qi::LogLevel verbosity (SubscriberId sub=0)
std::vector< std::string > categories ()
void setVerbosity (const std::string &rules, SubscriberId sub=0)
void setVerbosity (const qi::LogLevel lv, SubscriberId sub=0)
 Set log verbosity.
CategoryType addCategory (const std::string &name)
 Add/get a category.
void enableCategory (const std::string &cat, SubscriberId sub=0)
 Set.
void disableCategory (const std::string &cat, SubscriberId sub=0)
 Set.
void setCategory (const std::string &cat, qi::LogLevel level, SubscriberId sub=0)
 Set per-subscriber.
bool isVisible (CategoryType category, qi::LogLevel level)
bool isVisible (const std::string &category, qi::LogLevel level)
void setContext (int ctx)
 Set log context verbosity.
int context ()
 Get log context.
void setColor (LogColor color)
LogColor color ()
void setSynchronousLog (bool sync)
 Enables or disables synchronous logs.
SubscriberId addLogHandler (const std::string &name, qi::log::logFuncHandler fct, qi::LogLevel defaultLevel=LogLevel_Info)
void removeLogHandler (const std::string &name)
 Remove a log handler.
void flush ()
 Flush asynchronous logs.
QI_API_DEPRECATED void setVerbosity (SubscriberId sub, const qi::log::LogLevel lv)
QI_API_DEPRECATED void setCategory (SubscriberId sub, const std::string &cat, qi::log::LogLevel level)

Variables

QI_API_DEPRECATED typedef
qi::LogLevel 
LogLevel
QI_API_DEPRECATED typedef
unsigned int 
Subscriber

Detailed Description

Log functions with different levels of verbosity.

Each log has a category defined by the call to QI_LOG_CATEGORY() found in scope. So you must call QI_LOG_CATEGORY at least once, for instance at the beginning of your source file or function.

Logging is performed by invoking the QiLog* macro families, one per severity level: QiLogError, QiLogWarning, QiLogInfo, QiLogVerbose, and QiLogDebug. Those macros accept either a format syntax inside them, or a stream syntax outside.

 *
 * .. code-block:: cpp
 *
 * {
 *   qiLogCategory(my.category);
 *   qiLogInfoF("1 + 1 is %s", 1+1);
 *   qiLogInfo() << "1 + 1 is " << 1+1;
 * }
 *
 * 

Listeners for all log messages can be added with addLogHandler().

Logs can be filtered per-listener per-category with setCategory() Globbing is supported each time a category name must be specified:

 *   setCategory("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
 *
 * 

Typedef Documentation

typedef detail::Category * qi::log::CategoryType

Definition at line 210 of file log.hxx.

Boost delegate to log function (verbosity lv, date of log, category, message, file, function, line).

Definition at line 149 of file log.hpp.

typedef unsigned int qi::log::SubscriberId

Definition at line 136 of file log.hpp.


Function Documentation

CategoryType qi::log::addCategory ( const std::string &  name)

Add/get a category.

SubscriberId qi::log::addLogHandler ( const std::string &  name,
qi::log::logFuncHandler  fct,
qi::LogLevel  defaultLevel = LogLevel_Info 
)
std::vector<std::string> qi::log::categories ( )
Returns:
the list of existing categories

Get log context.

Returns:
Returns the level of context verbosity.

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.

Parameters:
catto silent log level. Globbing is supported.
void qi::log::enableCategory ( const std::string &  cat,
SubscriberId  sub = 0 
)

Set.

Parameters:
catto current verbosity level. Globbing is supported.

Flush asynchronous logs.

init the logging system (could be avoided)

Parameters:
verbLog verbosity
ctxDisplay Context
synchronousSynchronous log?
bool qi::log::isVisible ( CategoryType  category,
qi::LogLevel  level 
)
Returns:
true if given combination of category and level is enabled.
bool qi::log::isVisible ( const std::string &  category,
qi::LogLevel  level 
)
Returns:
true if given combination of category and level is enabled.
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.

Parameters:
verbThe verbosity of the message.
categoryLog category (for filtering in the future).
msgLog message.
fileFilename from which this function was called (ex: __FILE__).
fctFunction name from which this function was called (ex: __FUNCTION__).
lineLine 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 
)
const char* qi::log::logLevelToString ( const qi::LogLevel  verb,
bool  verbose = true 
)
qi::log::removeLogHandler ( const std::string &  name)

Remove a log handler.

Parameters:
nameName of the handler.
Examples:
log_example.cpp.
void qi::log::setCategory ( const std::string &  cat,
qi::LogLevel  level,
SubscriberId  sub = 0 
)

Set per-subscriber.

Parameters:
catto level
level.Globbing is supported.
QI_API_DEPRECATED void qi::log::setCategory ( SubscriberId  sub,
const std::string &  cat,
qi::log::LogLevel  level 
) [inline]

Definition at line 237 of file log.hpp.

void qi::log::setColor ( LogColor  color)
qi::log::setContext ( int  ctx)

Set log context verbosity.

Display log context (line, function, file).

Parameters:
ctxValue to set context.
 * Context values possible:
 *
 * - 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.

Enables or disables synchronous logs.

Set logs synchronicity

When setting to async, this function must be called after main has started.

Parameters:
syncValue to set or unset synchronous.
Examples:
log_example.cpp.
void qi::log::setVerbosity ( const std::string &  rules,
SubscriberId  sub = 0 
)

Parse and execute a set of verbosity rules Colon separated of rules. Each rule can be:

  • (+)?CAT : enable category CAT
  • -CAT : disable category CAT
  • CAT=level : set category CAT to level

Each category can include a '*' for globbing.

Examples:
log_example.cpp.
qi::log::setVerbosity ( const qi::LogLevel  lv,
SubscriberId  sub = 0 
)

Set log verbosity.

Parameters:
lvDefault verbosity level shown in the logs.
Note:
the level set by this function is a default value, overriden by all setCategory() calls.

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

QI_API_DEPRECATED void qi::log::setVerbosity ( SubscriberId  sub,
const qi::log::LogLevel  lv 
) [inline]

Definition at line 235 of file log.hpp.

qi::log::stringToLogLevel ( const char *  verb)

Convert string to log verbosity.

Parameters:
verbdebug, verbose, info, warning, error, fatal, silent
Returns:
Log level verbosity
qi::LogLevel qi::log::verbosity ( SubscriberId  sub = 0)

Variable Documentation

Definition at line 126 of file log.hpp.

QI_API_DEPRECATED typedef unsigned int qi::log::Subscriber

Definition at line 140 of file log.hpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines