spdl/0000755000176200001440000000000014443575442011230 5ustar liggesusersspdl/NAMESPACE0000644000176200001440000000010414330522725012431 0ustar liggesusersimportFrom(RcppSpdlog,log_set_level) exportPattern("^[[:alpha:]]+") spdl/ChangeLog0000644000176200001440000000504714443572272013006 0ustar liggesusers2023-06-18 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Release 0.0.5 * DESCRIPTION (Imports): Require RcppSpdlog 0.0.13 or later * DESCRIPTION(Title): Minor edit 2023-06-14 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll micro version and date * R/wrap.R (log): Define two simple setup aliases 'init()' and 'log' requiring only a level and setting a default display name of 'R' * man/setup.Rd: Update docs 2023-01-08 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Release 0.0.4 * R/wrap.R: Document stopwatch * man/setup.Rd: Ditto 2023-01-06 Dirk Eddelbuettel * R/wrap.R (fmt): Small robustification 2022-12-26 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll minor version and date * R/wrap.R (stopwatch,elapsed): Wrap two stopwatch functions 2022-12-14 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Release 0.0.3 * DESCRIPTION (Imports): Update versioned imports on RcppSpdlog, (Remotes): Remove RcppSpdlog 2022-12-13 Dirk Eddelbuettel * DESCRIPTION (Version, Date, Remotes): Roll minor version and date; add remote for rcppspdlog * R/wrap.R (filesetup): Add filesetup method 2022-12-01 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Release 0.0.2 * README.md (spdl): More edits 2022-11-29 Dirk Eddelbuettel * README.md (spdlog): Minor edits 2022-11-26 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll minor version and date * tests/simpleTest.R: Add simple tests for cat() and fmt() * tests/simpleTest.Rout.save: Reference output 2022-11-24 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll minor version and date * DESCRIPTION (BugReports, URL): Added 2022-11-22 Dirk Eddelbuettel * R/wrap.R (fmt, cat): Export cat() and fmt() * README.md: Add badges, small edits 2022-11-21 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Initial release 0.0.1 * R/wrap.R (.fmt): Do not use \dontrun * man/setup.Rd: Idem * README.md: Small edits * DESCRIPTION: Idem 2022-11-17 Dirk Eddelbuettel * inst/NEWS.Rd: Added * tests/simpleTest.R: Idem * tests/simpleTest.Rout.save: Idem 2022-11-16 Dirk Eddelbuettel * DESCRIPTION: Initial commit * NAMESPACE: Idem * README.md: Idem * R/init.R: Idem * R/wrap.R: Idem * man/setup.Rd: Idem * .github/workflows/ci.yaml: Added * .Rbuildignore: Idem * .gitignore: Idem spdl/README.md0000644000176200001440000001017714360066111012477 0ustar liggesusers ## spdl: A consistent C++ and R interface to spdlog [![CI](https://github.com/eddelbuettel/spdl/actions/workflows/ci.yaml/badge.svg)](https://github.com/eddelbuettel/spdl/actions/workflows/ci.yaml) [![CRAN](https://www.r-pkg.org/badges/version/spdl)](https://cran.r-project.org/package=spdl) [![Dependencies](https://tinyverse.netlify.com/badge/spdl)](https://cran.r-project.org/package=spdl) [![Downloads](https://cranlogs.r-pkg.org/badges/spdl?color=brightgreen)](https://www.r-pkg.org/pkg/spdl) [![License](https://img.shields.io/badge/license-GPL%20%28%3E=%202%29-brightgreen.svg?style=flat)](https://www.gnu.org/licenses/gpl-2.0.html) [![Last Commit](https://img.shields.io/github/last-commit/eddelbuettel/spdl)](https://github.com/eddelbuettel/spdl) ## About The [RcppSpdlog](https://github.com/eddelbuettel/rcppspdlog) repository (and [CRAN package](https://cran.r-project.org/package=RcppSpdlog)) provides access to the wonderful [spdlog](https://github.com/gabime/spdlog) library along with the [fmt](https://github.com/fmtlib/fmt) library. This permits use in C++ extensions for R by offering the [spdlog](https://github.com/gabime/spdlog) (header-only) library along with the (header-only) [fmt](https://github.com/fmtlib/fmt) library (by using `LinkingTo` as described in [Section 1.1.3 of WRE](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-Dependencies)). More recently, [RcppSpdlog](https://github.com/eddelbuettel/rcppspdlog) was extended so that it provides a set of key functions directly for use by other R functions (as described in [Section 5.4.3 of WRE](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Linking-to-native-routines-in-other-packages)). However, now the use of, say, a debug logging message from C++ looks like ```c++ // in C++ spdlog::debug("Text with {} text {} which is {}", "auto", "expansion", 42); ``` whereas in R, given the `RcppSpdlog` package and namespace, it looks like this (if we use `sprintf()` to assemble the message) ```R # in R RcppSpdlog::log_debug(sprintf("Text with %s text %s which is %s", "auto", "expansion", 42L) ``` and that irked us. Enter this package! By owning the `spld` namespace (in R) and an easily overlayed namespace in C++ of the same name we can do ```c++ // in C++ spdl::debug("Text with {} text {} which is {}", "auto", "expansion", 42); ``` as well as (still using `sprintf()`) ```R # in R spdl::debug(sprintf("Text with %s text %s which is %s", "auto", "expansion", 42L)) ``` which is _much better_ as it avoids context switching. Better still, with the internal formatter we can write the _same format string as in C++ and not worry about format details_: ```R # in R spdl::debug("Text with {} text {} which is {}", "auto", "expansion", 42L) ``` ## Details We use a simple mechanism in which all R arguments are passed through `format()` by default to render strings, and then pass a single vector of strings argument _through the restrictive C language Foreign Function Interface_ to [RcppSpdlog](https://github.com/eddelbuettel/rcppspdlog) where it can be passed to the C++ layer available there. This also means we use the [fmt](https://github.com/fmtlib/fmt) library in both languages as the formatter. We prefer this is over other string-interpolating libraries in R which are similar but subtly different. Should their use be desired, they can of course be used: the default call to any of the loggers is just a single-argument call with a text variable so users are free to expand strings as they please. Anything starting from `paste` and `sprintf` works. As of release 0.0.2, we also expose helpers `spdl::fmt()` (to format) and `spdl::cat()` (to display). ## Namespace Note that because the package uses functions names also present in the base R packages (namely `cat`, `debug`, `drop`, `trace`) we do *not* recommend loading the package. Instead, call it with the explicit prefix as _e.g._ `spdl::debug("Some message {}", foo)`. As a selective `importFrom` one can always do `importFrom("spdl", "setup")` combined with the explicit pre-fix use. ### Author Dirk Eddelbuettel ### License spdl is released under the GNU GPL, version 2 or later, just like R itself. spdl/man/0000755000176200001440000000000014334735416012001 5ustar liggesusersspdl/man/setup.Rd0000644000176200001440000000441014442337126013423 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/wrap.R \name{setup} \alias{setup} \alias{init} \alias{log} \alias{filesetup} \alias{drop} \alias{set_pattern} \alias{set_level} \alias{trace} \alias{debug} \alias{info} \alias{warn} \alias{error} \alias{critical} \alias{fmt} \alias{cat} \alias{stopwatch} \alias{elapsed} \title{Convenience Wrappers for 'RcppSpdlog' Logging From 'spdlog'} \usage{ setup(name = "default", level = "warn") init(level = "warn") log(level = "warn") filesetup(s, name = "default", level = "warn") drop(s) set_pattern(s) set_level(s) trace(s, ...) debug(s, ...) info(s, ...) warn(s, ...) error(s, ...) critical(s, ...) fmt(s, ...) cat(...) stopwatch() elapsed(w) } \arguments{ \item{name}{Character value for the name of the logger instance} \item{level}{Character value for the logging level} \item{s}{Character value for filename, pattern, level, or logging message} \item{...}{Supplementary arguments for the logging string} \item{w}{Stopwatch object} } \value{ Nothing is returned from these functions as they are invoked for their side-effects. } \description{ Several short wrappers for functions from 'RcppSpdlog' package are provided as a convenience. Given the potential for clashing names of common and popular functions names we do \emph{not} recommend the import the whole package but rather do \code{importFrom(RcppSpdlog, set_pattern)} (or maybe \code{importFrom(RcppSpdlog, set_pattern)}). After that, functionality can be accessed via a convenient shorter form such as for example \code{spdl::info()} to log at the \sQuote{info} level. Format strings suitable for the C++ library \sQuote{fmtlib::fmt} and its \code{fmt::format()} (which as of C++20 becomes \sQuote{std::fmt}) are supported so the \code{\{\}} is the placeholder for simple (scalar) arguments (for which the default R formatter is called before passing on a character representation). } \examples{ spdl::setup("exampleDemo", "warn") # and spdl::init("warn") and spdl::log("warn") are shortcuts spdl::info("Not seen as level 'info' below 'warn'") spdl::warn("This warning message is seen") spdl::set_level("info") spdl::info("Now this informational message is seen too") spdl::info("Calls use fmtlib::fmt {} as we can see {}", "under the hood", 42L) } spdl/DESCRIPTION0000644000176200001440000000175514443575442012746 0ustar liggesusersPackage: spdl Type: Package Title: Easier Use of 'RcppSpdlog' Functions via Wrapper Description: Logging functions in 'RcppSpdlog' provide access to the logging functionality from the 'spdlog' 'C++' library. This package offers shorter convenience wrappers for the 'R' functions which match the 'C++' functions, namely via, say, 'spdl::debug()' at the debug level. The actual formatting is done by the 'fmt::format()' function from the 'fmtlib' library (that is also 'std::format()' in 'C++20' or later). Version: 0.0.5 Date: 2023-06-18 Authors@R: person("Dirk", "Eddelbuettel", role = c("aut","cre"), email = "edd@debian.org") License: GPL (>= 2) Imports: RcppSpdlog (>= 0.0.13) URL: https://github.com/eddelbuettel/spdl BugReports: https://github.com/eddelbuettel/spdl/issues RoxygenNote: 6.0.1 NeedsCompilation: no Packaged: 2023-06-18 12:12:50 UTC; edd Author: Dirk Eddelbuettel [aut, cre] Maintainer: Dirk Eddelbuettel Repository: CRAN Date/Publication: 2023-06-18 12:40:02 UTC spdl/tests/0000755000176200001440000000000014443572026012365 5ustar liggesusersspdl/tests/simpleTest.R0000644000176200001440000000125514340451702014635 0ustar liggesusers spdl::setup("demoForTest", "warn") # new logger spdl::set_pattern("[%n] [%l] %v"); # special pattern _without time or pid_ for Rout.save use spdl::trace("This will not be seen.") spdl::debug("Neither will this.") spdl::info("Nor this.") spdl::warn("But we will see this message") spdl::warn("Format {} and {} and {}", 42L, 1.23, TRUE) spdl::set_level("debug") spdl::trace("This will still not be seen.") spdl::debug("But this will: {}.", "Yay!!") spdl::info("And this. {} and {}", 42L, 43) dt <- as.Date("2022-11-26") txt <- spdl::fmt("Int {} Double {} Bool {} Date {}", 42L, 1.23, TRUE, dt) cat(txt, "\n") spdl::cat("Int {} Double {} Bool {} Date {}", 42L, 1.23, TRUE, dt) spdl/tests/simpleTest.Rout.save0000644000176200001440000000327514340452033016324 0ustar liggesusers R version 4.2.2 Patched (2022-11-10 r83330) -- "Innocent and Trusting" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > spdl::setup("demoForTest", "warn") # new logger > spdl::set_pattern("[%n] [%l] %v"); # special pattern _without time or pid_ for Rout.save use > > spdl::trace("This will not be seen.") > spdl::debug("Neither will this.") > spdl::info("Nor this.") > spdl::warn("But we will see this message") [demoForTest] [warning] But we will see this message > spdl::warn("Format {} and {} and {}", 42L, 1.23, TRUE) [demoForTest] [warning] Format 42 and 1.23 and TRUE > > spdl::set_level("debug") > spdl::trace("This will still not be seen.") > spdl::debug("But this will: {}.", "Yay!!") [demoForTest] [debug] But this will: Yay!!. > spdl::info("And this. {} and {}", 42L, 43) [demoForTest] [info] And this. 42 and 43 > > dt <- as.Date("2022-11-26") > txt <- spdl::fmt("Int {} Double {} Bool {} Date {}", 42L, 1.23, TRUE, dt) > cat(txt, "\n") Int 42 Double 1.23 Bool TRUE Date 2022-11-26 > > spdl::cat("Int {} Double {} Bool {} Date {}", 42L, 1.23, TRUE, dt) Int 42 Double 1.23 Bool TRUE Date 2022-11-26 > > proc.time() user system elapsed 0.144 0.011 0.150 spdl/R/0000755000176200001440000000000014442337071011422 5ustar liggesusersspdl/R/wrap.R0000644000176200001440000000637714442337071012533 0ustar liggesusers ##' Convenience Wrappers for 'RcppSpdlog' Logging From 'spdlog' ##' ##' Several short wrappers for functions from 'RcppSpdlog' package are provided ##' as a convenience. Given the potential for clashing names of common and popular ##' functions names we do \emph{not} recommend the import the whole package but rather ##' do \code{importFrom(RcppSpdlog, set_pattern)} (or maybe \code{importFrom(RcppSpdlog, ##' set_pattern)}). After that, functionality can be accessed via a convenient shorter ##' form such as for example \code{spdl::info()} to log at the \sQuote{info} level. ##' Format strings suitable for the C++ library \sQuote{fmtlib::fmt} and its ##' \code{fmt::format()} (which as of C++20 becomes \sQuote{std::fmt}) are supported ##' so the \code{\{\}} is the placeholder for simple (scalar) arguments (for which the ##' default R formatter is called before passing on a character representation). ##' ##' @param name Character value for the name of the logger instance ##' @param level Character value for the logging level ##' @param s Character value for filename, pattern, level, or logging message ##' @param w Stopwatch object ##' @param ... Supplementary arguments for the logging string ##' @return Nothing is returned from these functions as they are invoked for their side-effects. ##' @examples ##' spdl::setup("exampleDemo", "warn") ##' # and spdl::init("warn") and spdl::log("warn") are shortcuts ##' spdl::info("Not seen as level 'info' below 'warn'") ##' spdl::warn("This warning message is seen") ##' spdl::set_level("info") ##' spdl::info("Now this informational message is seen too") ##' spdl::info("Calls use fmtlib::fmt {} as we can see {}", "under the hood", 42L) setup <- function(name = "default", level = "warn") RcppSpdlog::log_setup(name, level) ##' @rdname setup init <- function( level = "warn") RcppSpdlog::log_setup("R", level) ##' @rdname setup log <- function( level = "warn") RcppSpdlog::log_setup("R", level) ##' @rdname setup filesetup <- function(s, name = "default", level = "warn") RcppSpdlog::log_filesetup(s, name, level) ##' @rdname setup drop <- function(s) RcppSpdlog::log_drop(s) ##' @rdname setup set_pattern <- function(s) RcppSpdlog::log_set_pattern(s) ##' @rdname setup set_level <- function(s) RcppSpdlog::log_set_level(s) ##' @rdname setup trace <- function(s, ...) RcppSpdlog::log_trace(fmt(s,...)) ##' @rdname setup debug <- function(s, ...) RcppSpdlog::log_debug(fmt(s,...)) ##' @rdname setup info <- function(s, ...) RcppSpdlog::log_info(fmt(s,...)) ##' @rdname setup warn <- function(s, ...) RcppSpdlog::log_warn(fmt(s,...)) ##' @rdname setup error <- function(s, ...) RcppSpdlog::log_error(fmt(s,...)) ##' @rdname setup critical <- function(s, ...) RcppSpdlog::log_critical(fmt(s,...)) ##' @rdname setup fmt <- function(s, ...) { n <- ...length() v <- character(n) for (i in seq_len(n)) v[i] <- format(...elt(i)[1]) RcppSpdlog::formatter(s, v) # actual fmtlib::fmt formatting } ##' @rdname setup cat <- function(...) { base::cat(fmt(...), "\n") } ##' @rdname setup stopwatch <- function() RcppSpdlog::get_stopwatch() ##' @rdname setup elapsed <- function(w) RcppSpdlog::elapsed_stopwatch(w) spdl/R/init.R0000644000176200001440000000052114352133552012504 0ustar liggesusers .onAttach <- function(libname, pkgname) { txt <- paste0("\nThe 'spdl' package is not meant for interactive work following 'library(spdl)'.\n", "Rather, just call its functions directly (e.g. 'spdl::info(\"Some message\")')\n", "without attaching the package.\n") packageStartupMessage(txt) } spdl/MD50000644000176200001440000000073014443575442011540 0ustar liggesusersc1bd263ac9ca59f2ccb970fccab3189d *ChangeLog 57f90e3bed4f54279e4ceb89a771b13b *DESCRIPTION bb9082f47abae5823fe937d5a71e929c *NAMESPACE fae3f6dadfe9bf06fa90cd32996e854f *R/init.R 8ac0f810d33f5bbfdf7d4ae9171d617c *R/wrap.R 7bacabb5ab90ac3befa43b1772aa3888 *README.md aafbaf0b11402e3e8c527119e0ba8197 *inst/NEWS.Rd c6675a8f813ed9e22741ea27c9eb4d85 *man/setup.Rd f14494e0920a481aab5cea7a4cd8f513 *tests/simpleTest.R ebbe8e016f997803c12c5e7c2bb35f8b *tests/simpleTest.Rout.save spdl/inst/0000755000176200001440000000000014443571752012205 5ustar liggesusersspdl/inst/NEWS.Rd0000644000176200001440000000164714443571752013260 0ustar liggesusers\name{NEWS} \title{News for Package \pkg{spdl}} \newcommand{\ghpr}{\href{https://github.com/eddelbuettel/spdl/pull/#1}{##1}} \newcommand{\ghit}{\href{https://github.com/eddelbuettel/spdl/issues/#1}{##1}} \section{Changes in spdl version 0.0.5 (2023-06-18)}{ \itemize{ \item Add simple aliases \code{init()} and \code{log()} wrapping \code{setup()} but requiring only the logging level argument } } \section{Changes in spdl version 0.0.4 (2023-01-08)}{ \itemize{ \item Add support for \code{stopwatch} } } \section{Changes in spdl version 0.0.3 (2022-12-14)}{ \itemize{ \item Add \code{filesetup} method } } \section{Changes in spdl version 0.0.2 (2022-12-01)}{ \itemize{ \item Helper functions \code{fmt()} and \code{cat()} have been added } } \section{Changes in spdl version 0.0.1 (2022-11-21)}{ \itemize{ \item Initial release of R and C++ loggers using \code{spdl::*} namespace } }