pid-log  3.1.8

pid-log package provides a little API to manage logs in a clean and really configurable way. It is based on Boost.Log meta logging system. Its usage is completely bound to the use of PID system.


The pid-log package implement the runtime logging facility of PID. By logging we mean generating messages that inform about the state of a running program. These messages can be read from standard outputs or files and may be useful to notify some tools of interesting events, to provide debug information to developpers, or traces of program execution.

pid-log intend to provide a powerful but easy to configure logging tool for developpers with features:

  • possibility to deactivate logs for a the whole program. Useful when you want to get real-time compatible performance and log is not required.
  • filtering log messages either according to their severity or depending on their emitting place (component, package, framework).
  • generating various log outputs from the same global log trace in a program. For instance usefull to discriminate errors or debug traces from other information.
  • formatting of log messages is standardized and can be configured to get various information such as: calling site information (line in source file, calling function), runtime trace generation (date, thread) or PID related information (framework, package, component of the emitting component).
  • easy configuration of logger system at global level. This way libraries can be completely agnostic from the way logs they generate are finally managed.


Basically, to use logging system of PID, a package (let's call ot my-package) needs to depend on the pid-log package. In root CMakeLists.txt of the package:

PID_Dependency(pid-log VERSION 3.1)
# or PID_Dependency(pid-log) to get latest version

Then for a component my-component that needs to generate log traces, in the adequate CMakeLists.txt:

PID_Component( my-component

The LOGGABLE argument tells PID to generate a specific header file (in the current example pid/log/my-package_my-component.h) that is included in public headers of my-component.

Then in my-component source code:

#include <pid/log/my-package_my-component.h>
void my_function(){
int error_number=0;
pid_log << pid::error << "error number: " << error_number <<pid::flush;
if(strange_case_to_test > 0.0){
pid_log << pid::debug << "bad situation "<< strange_case_to_test << pid::flush;

The pid_log object is used to access logging system: it is used as a stream operator to generate log trace, with first input being the severity (e.g. pid::error). The log trace is generated when pid::flush is inserted in this stream, allowing trace construction on multiple lines of code if needed.

Now let's suppose that component my-application depends on my-component, it can control log traces generated by the library

#include <my/component.h>//global header for my-component
#include <pid/log.h>
int main(int argc, char * argv[]){
//or pid::logger().configure("pid_log/only_errors_logs.yaml");

In this example only traces generated with pid::error or pid::critical modifiers will be printed to standard output. The PID_LOGGER macro gives you the access to the global logger object. If the logger is not configured explicilty of if the program use the "pid_log/default_logs.yaml" then everything except debug traces will be printed to standard output. There are a few base configurations for the logger but you can define new ones (writing to specific file, standard error, filtering traces coming from specific libraries, etc.).

With default configruation, output in terminal would look like (no debug trace printed):

[error] error number: 0
[error] error number: 1

Otherwise, you may want to deactivate all logs:

#include <my/component.h>//global header for my-component
#include <pid/log.h>
int main(int argc, char * argv[]){
//or PID_LOGGER.configure("pid_log/deactivated_logs.yaml");

And nothing will be printed in console.

There are a few things to learn to use all the power of pid-log system, please read the online tutorial for more details.

The license that applies to the whole package content is CeCILL-C. Please look at the license.txt file at the root of this repository for more details.

About authors

pid-log has been developed by following authors:

  • Robin Passama (CNRS/LIRMM)

Please contact Robin Passama ( - CNRS/LIRMM for more information or questions.

root namespace for pid packages.
Definition: logger.h:37
#define pid_log
provide a stream like proxy object used to generate messages
Definition: log.h:71
#define PID_LOGGER
provide acess to the global logger core.
Definition: log.h:77
this is the user API of the logging system.
PID_LOG_PID_LOG_EXPORT pid::log::Proxy & error(pid::log::Proxy &logger)
pid::error write the output message as an error.
PID_LOG_PID_LOG_EXPORT pid::log::Proxy & flush(pid::log::Proxy &logger)
pid::flush flush the output of a logger proxy..
PID_LOG_PID_LOG_EXPORT pid::log::Proxy & debug(pid::log::Proxy &logger)
pid::debug write the output message as a debug message.