The 'plog' C++ Logging Library

A simple header-only logging library for C++. Add 'LinkingTo: plogr' to 'DESCRIPTION', and '#include ' in your C++ modules to use it.

Provides the header files for a stripped-down version of the plog header-only C++ logging library, and a method to log to R's standard error stream.

You can install plogr from GitHub with:


Add LinkingTo: plogr to your DESCRIPTION, and add #include <plogr.h> to all modules where you want to access the logging. If your package has an univeral header file which you include from all modules, it's probably a good idea to insert the #include directive there, so that all of your code has access to logging. The following system header files will be included:

  • sstream
  • iostream
  • vector
  • cassert
  • cstring
  • time.h (on Linux/OS X)
  • sys/time.h (on Windows)
  • R.h

The code shows a small usage example and a demo which we'll call from R below. (Rcpp is not necessary to use plogr, it is only needed to run the C++ code chunk.) The init_r() function is the only new function added by the R package, and initializes a logger that logs to R's standard error stream. For further details consult the plog documentation; for compatibility reasons you won't find the file appenders in this package.

// [[Rcpp::depends(plogr)]] 
#include <plogr.h>
// [[Rcpp::export]] 
void plogr_demo() {
  LOG_INFO << "test 1";
  LOG_INFO << "test 2";
  LOG_DEBUG << "test 3";
  plog::init_r("DEBUG"); // You can also pass a string 
  LOG_INFO << "test 4";
  LOG_DEBUG << "test 5";
#include <Rcpp.h> // not necessary to use plogr 

The R code below calls the plogr_demo() C++ function defined above. Currently, the messages are printed straight to the standard error stream, so the message capturing mechanisms employed by knitr don't work. We use a sink with a text connection to capture the messages, and print the contents of the variable to which the text connection assigns.

output <- character()
con <- textConnection("output", "a")
withr::with_message_sink(con, plogr_demo())
cat(output, sep = "\n")
#> plogr_demo@8: test 2
#> plogr_demo@11: test 4
#> plogr_demo@12: test 5

Nothing is printed before we actually initialize the logger. Because it is initialized to the info level, the debug log message is not shown, and only "test 2" comes through. After changing the log level, the debug message is also shown.


  • Remove useless operator overloads.
  • Reword description.

plogr 0.1 (2016-09-24)

  • Using a stripped version of plog 1.0-1.
  • Works on Linux, OS X, and Windows.
  • Log items are printed using.
  • New plog::init_r() to initialize logging via REprintf(), allows changing the log level and passing the log level as string.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1-1 by Kirill Müller, 5 months ago

Report a bug at

Browse source code at

Authors: Kirill Müller [aut, cre], Sergey Podobry [cph] (Author of the bundled plog library)

Documentation:   PDF Manual  

MIT + file LICENSE license

Suggests Rcpp

Linked to by RSQLite, bindrcpp.

See at CRAN