MyNixOS website logo
Description

Tiny Logging Interface to 'rspdlite' Wrapping 'spdlite' C++20 Logging.

Just how 'spdl' provides a nice and consistent interface to 'spdlog' (via 'RcppSpdlog'), this package does so for 'spdlite', the lightweight header-only C++-20 logging library that provides a lighter version of 'spdlog'. This package is essentially a thin shim around it for a more compact interface from both R and C++.

tl: A tiny logger using spdlite via rspdlite

CI License CRAN Dependencies r-universe Last Commit

About

The rspdlite packages provides the tiny, fast, capable logger spdlite, implemented as a small C++20 header-only library, for use by R. It is related to its larger and more featureful cousing spdlog which we provide via RcppSpdlog -- and the wrapping frontend spdl which polishes and unifies some user-interface aspects for the discerning R user and/or package developer.

tl does the same for rspdlite: It offers an entirely optional interface consistently using namespaced calling convention for both R and C++. In other words, one can added debugging informations such as tl::info("Entering section foo") the same way in both R and C++ (with an added semicolon, or course, and by adding a header for declarations).

Examples

We can revisit the examples from the rspdlite package:

From C++

We can use the same C++ example from the spdlite docs, but now accessing via the tl namespace:

tl::critical("-- level to warn");
tl::set_level("warn");

tl::error("Some error message with arg: {}", 1);
tl::warn("Easy padding in numbers like {:08d}", 12);
tl::critical("Support for int: {0:d};  hex: {0:x};  oct: {0:o}; bin: {0:b}", 42);
tl::info("Support for floats {:03.2f}", 1.23456);
tl::info("Positional args are {1} {0}..", "too", "supported");
tl::info("{:<30}", "left aligned");

The default logging level is 'info' so all these message would appear by default but as we alter the logging level dynamically to 'warn' fewer messages appear.

From R

Following the nice user experience offered by spdl, we similarly provide access via the 'package name colon colon' patter from R:

tl::critical("-- level to debug")
tl::set_level("debug")

tl::info("Some more at info")
tl::error("Some error message with arg: {}", 1)
tl::error("Some error message with more args: {} and {}", 1, "abc")

tl::log_critical("-- level to error and calling example1 and example2")
tl::set_level("error")

As for its cousin R packages, the format string here 'resembles' the full C++ format string, but remains simpler. As we convert each argument directly to a character (then passed on to the C++ layer) we do not offer the extra formatting options available directly from C++. We have not found this to be an issue.

Package tlexample

The package tlexample offers a complete example of integrated logging from both C++ and R. After installing rspdlite and tl (along with their one dependency Rcpp) one can run the provided demo. So for example in an r2u container (such as rocker/r2u where we rely on the GitHub installation helper also pulling in dependencies Rcpp, rspdlite and this package tl as binaries)

root$ installGithub.r eddelbuettel/tlexample
root$ Rscript -e 'demo(ex, package="tlexample")'

or alternatively install Rcpp and these package from source or as binary from my r-universe. This tlexample package is very lightweight and therefore a good playground to experiment with logging via tl, rspdlite and spdlite.

Package RcppNLoptExample

The package RcppNLoptExample package (also on [CRAN][cran]) provides a complete example from the documentation of the underlying NLopt library, bundled in a small yet complete package illustrating use of NLopt from R. This offers a vessel for a good illustration of adding tl from both the C++ and R, along with different logging levels.

Author

Dirk Eddelbuettel

License

tl is released under the GNU GPL, version 2 or later, just like R itself.

Metadata

Version

0.0.2

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows