Thespdlog library isa widely-used and very capable header-only C++ library for logging. Thispackage includes its headers as an R package to permit other R packagesto deploy it via a simpleLinkingTo: RcppSpdlog asdescribed inSection1.1.3 of WRE.
A simple first example, following the upstream examples:
edd@rob:~$ Rscript-e'Rcpp::sourceCpp("inst/examples/exampleOne.cpp")'R> exampleOne()[07:45:57.168673] [I] [thread 1500593] Welcome to spdlog![07:45:57.168704] [E] [thread 1500593] Some error message with arg: 1[07:45:57.168707] [W] [thread 1500593] Easy padding in numbers like 00000012[07:45:57.168710] [C] [thread 1500593] Support for int: 42;hex: 2a;oct: 52;bin: 101010[07:45:57.168728] [I] [thread 1500593] Support for floats 1.23[07:45:57.168731] [I] [thread 1500593] Positional args are supported too..[07:45:57.168734] [I] [thread 1500593] left aligned[07:45:57.168737] [D] [thread 1500593] This message should be displayed..edd@rob:~$This logs the hour, minute, second, microsecond followed by aone-char code for info, error, warning or critical followed by thethread id and the actual loggable message. The code is included in thepackage.
Many other customizations are possible, see thespdlog wiki.
Note that usingspdlog examples directlymaywell trigger warning from R during package checking asstdout and/orstderr may be used. See theincluded example function described in the next section which uses aderived class to pass logging output explicitly to the R input/outputstream as per the R coding requirements, seeSection1.3.1 (and others) of WRE.
As shipped, bothspdlog and the embeddedfmt usestdout andstderr in ways that may make it non-trivial to fullyreplace them with R input/output as required bySection1.3.1 (and others) of WRE.
However, based on some initial trials and some excellent help fromupstream we have defined a specific sink for R in the headerrcpp_sink.h,corrected onestderr use and added one#define. That combination now passes as can be seen inchecks of the packageRcppSpdlog and the included functionexampleRsink() whose complete source code is included inthe package too.
Note that it is deliberately similar in use to the example above. Anew instance of the logger is instantiated as a shared pointersp to aspdlog object.
We may make additional package features available in the future.
Gabi Melman is the mainauthor ofspdlog.
Victor Zverovich is the mainauthor of the embeddedfmtlibrary.
Dirk Eddelbuettel isauthor of this package and the R integration.
spdlog andfmt are under the MITlicense.
RcppSpdlog is released under the GNU GPL, version 2 or later, justlike R and Rcpp.
Initially created: Wed Aug 19 08:01:13 CDT 2020
Last modified: Sun May 26 10:24:42 CDT 2024