diff --git a/docs/changelog/index.html b/docs/changelog/index.html index 011d314..7bb927c 100644 --- a/docs/changelog/index.html +++ b/docs/changelog/index.html @@ -746,6 +746,15 @@

Changelog

2024

+

2024-04-25 Dirk Eddelbuettel edd@debian.org

+
    * DESCRIPTION (Version, Date): Version 0.0.17
+
+    * inst/include/spdlog/*: New upstream release spdlog 1.14.0
+
+

2024-04-02 Dirk Eddelbuettel edd@debian.org

+
    * .github/workflows/ci.yaml (jobs): Update to actions/checkout@v4, 
+    add r-ci-setup actions
+

2024-01-12 Dirk Eddelbuettel edd@debian.org

    * DESCRIPTION (Version, Date): Version 0.0.16
 
diff --git a/docs/mkdmt-src/src/changelog.md b/docs/mkdmt-src/src/changelog.md
index 722e015..9af86ca 100644
--- a/docs/mkdmt-src/src/changelog.md
+++ b/docs/mkdmt-src/src/changelog.md
@@ -1,5 +1,16 @@
 ###  2024 
 
+2024-04-25  Dirk Eddelbuettel   
+ 
+        * DESCRIPTION (Version, Date): Version 0.0.17 
+ 
+        * inst/include/spdlog/*: New upstream release spdlog 1.14.0 
+ 
+2024-04-02  Dirk Eddelbuettel   
+ 
+        * .github/workflows/ci.yaml (jobs): Update to actions/checkout@v4, 
+        add r-ci-setup actions 
+ 
 2024-01-12  Dirk Eddelbuettel   
  
         * DESCRIPTION (Version, Date): Version 0.0.16 
diff --git a/docs/mkdmt-src/src/news.md b/docs/mkdmt-src/src/news.md
index d98867e..b099f24 100644
--- a/docs/mkdmt-src/src/news.md
+++ b/docs/mkdmt-src/src/news.md
@@ -1,8 +1,13 @@
-
-

News for Package RcppSpdlog

+
+
+

Version 0.0.17 (2024-04-25)

+
    +
  • Minor continuous integration update

  • +
  • Upgraded to upstream release spdlog 1.14.0

  • +

Version 0.0.16 (2024-01-12)

    -
  • Upgraded to upstream releases spdlog 1.13.0

  • +
  • Upgraded to upstream release spdlog 1.13.0

Version 0.0.15 (2023-11-29)

    @@ -14,7 +19,7 @@ R-devel

    Version 0.0.14 (2023-07-09)

    • Added new badge to README.md

    • -
    • Upgraded to upstream releases spdlog 1.12.0

    • +
    • Upgraded to upstream release spdlog 1.12.0

    Version 0.0.13 (2023-06-17)

      @@ -55,11 +60,11 @@ R

      spdlog

    • Update GitHub Actions to checkout@v3

    • Add a shorter aliased namespace for C++

    • -
    • Upgraded to upstream releases spdlog 1.11.0

    • +
    • Upgraded to upstream release spdlog 1.11.0

    Version 0.0.8 (2022-04-04)

      -
    • Upgraded to upstream releases spdlog 1.10.0

    • +
    • Upgraded to upstream release spdlog 1.10.0

    Version 0.0.7 (2021-12-05)

      @@ -106,4 +111,5 @@ compile-time logging switch example

      • Initial release with added R/Rcpp logging sink example

      -
+ + diff --git a/docs/news/index.html b/docs/news/index.html index e39422b..0d8dc28 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -640,11 +640,16 @@

News

-
-

News for Package RcppSpdlog

+
+
+

Version 0.0.17 (2024-04-25)

+
    +
  • Minor continuous integration update

  • +
  • Upgraded to upstream release spdlog 1.14.0

  • +

Version 0.0.16 (2024-01-12)

    -
  • Upgraded to upstream releases spdlog 1.13.0

  • +
  • Upgraded to upstream release spdlog 1.13.0

Version 0.0.15 (2023-11-29)

    @@ -656,7 +661,7 @@

    Version 0.0.15 (2023-11-29)

    Version 0.0.14 (2023-07-09)

    • Added new badge to README.md

    • -
    • Upgraded to upstream releases spdlog 1.12.0

    • +
    • Upgraded to upstream release spdlog 1.12.0

    Version 0.0.13 (2023-06-17)

      @@ -697,11 +702,11 @@

      Version 0.0.9 (2022-11-04)

      spdlog

    • Update GitHub Actions to checkout@v3

    • Add a shorter aliased namespace for C++

    • -
    • Upgraded to upstream releases spdlog 1.11.0

    • +
    • Upgraded to upstream release spdlog 1.11.0

    Version 0.0.8 (2022-04-04)

      -
    • Upgraded to upstream releases spdlog 1.10.0

    • +
    • Upgraded to upstream release spdlog 1.10.0

    Version 0.0.7 (2021-12-05)

      @@ -748,7 +753,8 @@

      Version 0.0.1 (2020-09-08)

      • Initial release with added R/Rcpp logging sink example

      -
+ + diff --git a/docs/search/search_index.json b/docs/search/search_index.json index 7e5ee0e..ee6c63d 100644 --- a/docs/search/search_index.json +++ b/docs/search/search_index.json @@ -1 +1 @@ -{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"Bundling of spdlog for use from R and Rcpp About The spdlog library is a widely-used and very capable header-only C++ library for logging. This package includes its headers as an R package to permit other R packages to deploy it via a simple LinkingTo: RcppSpdlog as described in Section 1.1.3 of WRE . As of version 0.0.9, it also provides both simple R logging functions and compiled functions callable by other packages as described in Section 5.4.3 of WRE . Example 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 a one-char code for info, error, warning or critical followed by the thread id and the actual loggable message. The code, apart from the included headers and more, is simply // [[Rcpp::export]] void exampleOne() { // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%L] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug(\"This message should be displayed..\"); // Compile time log levels // define SPDLOG_ACTIVE_LEVEL to desired level SPDLOG_TRACE(\"Some trace message with param {}\", {}); SPDLOG_DEBUG(\"Some debug message\"); } Many other customizations are possible, see the spdlog wiki . Note that using spdlog examples directly may well trigger warning from R during package checking as stdout and/or stderr may be used. See the included example function described in the next section which uses a derived class to pass logging output explicitly to the R input/output stream as per the R coding requirements, see Section 1.3.1 (and others) of WRE . Use in R Packages and Warnings As shipped, both spdlog and the embedded fmt use stdout and stderr in ways that may make it non-trivial to fully replace them with R input/output as required by Section 1.3.1 (and others) of WRE . However, based on some initial trials and some excellent help from upstream we have defined a specific sink for R in the header rcpp_sink.h , corrected one stderr use and added one #define . That combination now passes as can be seen in checks of the package RcppSpdlog and the included function exampleRsink() whose complete source code is included here: // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include //' spdlog Example using a sink for R //' //' A simple example invoking a derived R/Rcpp logger. Also demonstrates the //' stopwatch feature. For more features see the 'spdlog' documnetation. //' //' Note that this no longer triggers R warnings thanks to excellent help by //' Gabi Melman. //' @return None //' @examples //' exampleRsink() // [[Rcpp::export]] void exampleRsink() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed spdlog::stopwatch sw; // instantiate a stop watch // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::info(\"Elapsed time: {}\", sw); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::info(\"Elapsed time: {}\", sw); } Note that it is deliberately similar in use to the example above. A new instance of the logger is instantiated as a shared pointer sp to a spdlog object. Similarly, a stopwatch is instantiated used simply by referring to it. We may make additional package features available in the future. See Also The spdl package, now also on CRAN, wraps around this package to provide a uniform and consistent logging interface from both R and C++. It defines a new C++ namespace spdl along with matching R functions. Author Gabi Melman is the main author of spdlog . Victor Zverovich is the main author of the embedded fmt library. Dirk Eddelbuettel is author of this package and the R integration. License spdlog and fmt are under the MIT license. RcppSpdlog is released under the GNU GPL, version 2 or later, just like R and Rcpp.","title":"RcppSpdlog"},{"location":"#bundling-of-spdlog-for-use-from-r-and-rcpp","text":"","title":"Bundling of spdlog for use from R and Rcpp"},{"location":"#about","text":"The spdlog library is a widely-used and very capable header-only C++ library for logging. This package includes its headers as an R package to permit other R packages to deploy it via a simple LinkingTo: RcppSpdlog as described in Section 1.1.3 of WRE . As of version 0.0.9, it also provides both simple R logging functions and compiled functions callable by other packages as described in Section 5.4.3 of WRE .","title":"About"},{"location":"#example","text":"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 a one-char code for info, error, warning or critical followed by the thread id and the actual loggable message. The code, apart from the included headers and more, is simply // [[Rcpp::export]] void exampleOne() { // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%L] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug(\"This message should be displayed..\"); // Compile time log levels // define SPDLOG_ACTIVE_LEVEL to desired level SPDLOG_TRACE(\"Some trace message with param {}\", {}); SPDLOG_DEBUG(\"Some debug message\"); } Many other customizations are possible, see the spdlog wiki . Note that using spdlog examples directly may well trigger warning from R during package checking as stdout and/or stderr may be used. See the included example function described in the next section which uses a derived class to pass logging output explicitly to the R input/output stream as per the R coding requirements, see Section 1.3.1 (and others) of WRE .","title":"Example"},{"location":"#use-in-r-packages-and-warnings","text":"As shipped, both spdlog and the embedded fmt use stdout and stderr in ways that may make it non-trivial to fully replace them with R input/output as required by Section 1.3.1 (and others) of WRE . However, based on some initial trials and some excellent help from upstream we have defined a specific sink for R in the header rcpp_sink.h , corrected one stderr use and added one #define . That combination now passes as can be seen in checks of the package RcppSpdlog and the included function exampleRsink() whose complete source code is included here: // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include //' spdlog Example using a sink for R //' //' A simple example invoking a derived R/Rcpp logger. Also demonstrates the //' stopwatch feature. For more features see the 'spdlog' documnetation. //' //' Note that this no longer triggers R warnings thanks to excellent help by //' Gabi Melman. //' @return None //' @examples //' exampleRsink() // [[Rcpp::export]] void exampleRsink() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed spdlog::stopwatch sw; // instantiate a stop watch // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::info(\"Elapsed time: {}\", sw); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::info(\"Elapsed time: {}\", sw); } Note that it is deliberately similar in use to the example above. A new instance of the logger is instantiated as a shared pointer sp to a spdlog object. Similarly, a stopwatch is instantiated used simply by referring to it. We may make additional package features available in the future.","title":"Use in R Packages and Warnings"},{"location":"#see-also","text":"The spdl package, now also on CRAN, wraps around this package to provide a uniform and consistent logging interface from both R and C++. It defines a new C++ namespace spdl along with matching R functions.","title":"See Also"},{"location":"#author","text":"Gabi Melman is the main author of spdlog . Victor Zverovich is the main author of the embedded fmt library. Dirk Eddelbuettel is author of this package and the R integration.","title":"Author"},{"location":"#license","text":"spdlog and fmt are under the MIT license. RcppSpdlog is released under the GNU GPL, version 2 or later, just like R and Rcpp.","title":"License"},{"location":"changelog/","text":"2024 2024-01-12 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.16 * inst/include/spdlog/*: New upstream release spdlog 1.13.0 2023 2023-11-29 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.15 * src/RcppExports.cpp: Regenerated under updated Rcpp to address format string issue reported by R-devel * man/RcppSpdlog-package.Rd: Remove some empty default entries 2023-07-09 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.14 2023-07-08 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdlog/*: New upstream release spdlog 1.12.0 2023-06-28 Dirk Eddelbuettel edd@debian.org * README.md: Add r-universe badge 2023-06-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.13 2023-06-13 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp (log_init): Add a simple convenience wrapper to log_setup() which omits the first 'logger name' argument * inst/include/spdl.h: Define convenience wrappers init() and log() 2023-03-19 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/Makevars: No longer set a C++ standard * R/RcppExports.R (setLoadAction): Updated .Call using backticks 2023-01-17 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog_stopwatch.h: Define stopwatch without fmt.h header * inst/include/RcppSpdlog_types.h: Use spdlog_stopwatch if #define set 2023-01-07 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.12 2022 2022-12-27 Dirk Eddelbuettel edd@debian.org * src/interface.cpp: Add documentation reference for format pattern * man/log_setup.Rd: Idem * R/RcppExports.R: Idem 2022-12-25 Dirk Eddelbuettel edd@debian.org * inst/include/spdl.h: Wrap three RcppSpdlog::*_stopwatch() functions 2022-12-23 Dirk Eddelbuettel edd@debian.org * src/interface.cpp: Split stopwatch documentation off * man/get_stopwatch.Rd: Idem * man/log_setup.Rd: Idem * src/RcppExports.cpp: Idem * R/RcppExports.R: Idem 2022-12-22 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp: Define and document three new functions for stopwatch * R/RcppExports.R: Export new functions * src/RcppExports.cpp: Idem * inst/include/RcppSpdlog_RcppExports.h: Idem * inst/include/RcppSpdlog_types.h: Include stopwatch, add XPtr template * inst/include/RcppSpdlog: Use new header * man/log_setup.Rd: Add documentation * R/stopwatch.R: Add two S3 methods for stopwatch objects * NAMESPACE: Export methods * inst/include/rcpp_sink.h: Use lighter Rcpp interface 2022-12-13 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.11 * vignettes/introduction.md: Microedit 2022-12-12 Dirk Eddelbuettel edd@debian.org * src/interface.cpp (log_filesetup): Setup (simple) file-based logger * R/RcppExports.R: R accessor * src/RcppExports.cpp: Autogenerated export for C level access * inst/include/RcppSpdlog_RcppExports.h: Idem * inst/include/rcpp_sink.h: Added #include * man/log_setup.Rd: Added documentation * inst/include/spdl.h: Added in spdl namespace 2022-12-02 Dirk Eddelbuettel edd@debian.org * README.md: Mention the new spdl package 2022-11-18 Dirk Eddelbuettel edd@debian.org * src/formatter.cpp: Export to C++ to make formatter() callable * src/RcppExports.cpp: Autogenerated export for C level access * inst/include/RcppSpdlog_RcppExports.h: Idem 2022-11-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.10 * vignettes/introduction.md: More edits 2022-11-15 Dirk Eddelbuettel edd@debian.org * src/formatter.cpp (formatter): Add formatting helper which passes logging string to fmt::format() enable fmt's \"format\" from R * src/RcppExports.cpp: Ditto * R/RcppExports.R (formatter): Ditto * man/formatter.Rd: Docs * inst/include/spdl.h: Include fmtlib::fmt via spdlog 2022-11-14 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdl.h: Use variadic templates to fmt::format 2022-11-04 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.9 2022-11-03 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdlog/*: New upstream release spdlog 1.11.0 * vignettes/introduction.md: Small edits 2022-11-02 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.md: New sections for access from R and C++ 2022-11-01 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/RcppSpdlog: Ad second shorter namespace 'spdl' with shorter (inlined) function names as simpler accessors * vignettes/introduction.md: Two new sections on access from R and C++, respectively 2022-10-31 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version 2022-10-30 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp: Add R interface to spdlog * man/log_setup.Rd: Documentation * .github/workflows/ci.yaml (jobs): Update to actions/checkout@v3 * src/interface.cpp: Activate R and C++ interface generation * R/RcppExports.R: Updated accordingly * src/RcppExports.cpp: Idem * inst/include/RcppSpdlog.h: Generated * inst/include/RcppSpdlog_RcppExports.h: Idem 2022-04-04 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.8 * inst/include/spdlog/*: New upstream release spdlog 1.10.0 2021 2021-12-05 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.7 2021-11-20 Dirk Eddelbuettel edd@debian.org * vignettes/water.css: Added css file 2021-11-19 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * vignettes/introduction.md: Converted from Rmd to simplermarkdown * DESCRIPTION: Switched VignetteBuilder: to simplermarkdown 2021-08-12 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * inst/include/spdlog/*: New upstream release spdlog 1.9.2 2021-07-27 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * inst/include/spdlog/*: New upstream release spdlog 1.9.1 2021-07-21 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.6 * inst/include/spdlog/*: New upstream spdlog 1.9.0 (with fmt 8.x) 2021-03-28 Dirk Eddelbuettel edd@debian.org * docs/mkdmt-src/: Moved mkdocs-material input 2021-03-27 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.5 2021-03-25 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: New upstream release spdlog 1.8.4 + 1.8.5 2021-03-24 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Description): Mention Gabi explicitly (URL): List GitHub repo and package pages (BugReports): List GitHub issues pages * inst/include/spdlog/*: New upstream release spdlog 1.8.3 2020 2020-12-25 Dirk Eddelbuettel edd@debian.org * .github/workflows/ci.yaml: Small tweaks to CI YAML file 2020-12-11 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.4 * inst/include/spdlog/*: New upstream release spdlog 1.8.2 * .github/workflows/ci.yaml: Add CI runner using r-ci 2020-10-23 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.3 * docs/: Added package website * docs-src/: Added package website inputs 2020-10-19 Dirk Eddelbuettel edd@debian.org * README.md: Updated example 2020-10-08 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.Rmd (vignette): Compile-time example added 2020-10-04 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.Rmd (vignette): New (draft) vignette * DESCRIPTION (VignetteBuilder): Add knitr (Suggests): Add knitr, rmarkdown, minidown * inst/examples/exampleTwo.cpp (exampleTwo): Added cleanup at end with logger removal to permit multiple calls to example function * inst/examples/exampleThree.cpp (exampleThree): Idem 2020-10-01 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: Upgraded to upstream release 1.8.1 2020-09-30 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp (exampleRsink): Use default logger instance 2020-09-29 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp (setLogLevel): New function * R/RcppExports.R (exampleRsink): R accessor * man/setLogLevel.Rd: Documentation 2020-09-28 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/logger-inl.h: Synchronised with our PR #1685 switching to REprintf() if R_R_H and USING_R defined * inst/include/RcppSpdlog: Include R.h so that R_R_H and USING_R defined, define SPDLOG_DISABLE_DEFAULT_LOGGER here * src/exampleRsink.cpp: Removed SPDLOG_DISABLE_DEFAULT_LOGGER def. 2020-09-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.2 * inst/include/spdlog/*: Upgraded to upstream release 1.8.0 * inst/include/spdlog/logger-inl.h: Switch to REprintf as before * .travis.yml: Use BSPM, turn os macOS * src/exampleRsink.cpp (exampleRsink): Add 'stopwatch' demo 2020-09-08 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.1 2020-08-21 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp: Renamed from exampleFour() * man/exampleRsink.Rd: Idem * src/RcppExports.cpp: Updated * R/RcppExports.R: Idem * README.md: Some more edits 2020-08-20 Dirk Eddelbuettel edd@debian.org * inst/include/RcppSpdlog: Easy wrapper for spdlog and R sink * inst/include/rcpp_sink.h: A sink for R using Rcpp::Rcout * src/exampleFour.cpp: Rewritten and now R CMD check clean * inst/examples/examplesFour.cpp: Now in src/, R sink in its header * README.md: Edited, added two badges * cleanup: Added * .editorconfig: Idem 2020-08-19 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: Using spdlog version 1.7 * inst/examples/*: Four simple usage examples * .travis.yml: Added though no real tests present * src/exampleFour.cpp (exampleFour): Simple wrapper around simple Rcpp logger class which still triggers R warnings * man/exampleFour.Rd: Basic help page * src/RcppExports.cpp: Generated * src/Makevars: Added * R/RcppExports.R: Idem * NAMESPACE: Added * DESCRIPTION: Added Imports: and LinkingTo: for Rcpp","title":"Changelog"},{"location":"changelog/#2024","text":"2024-01-12 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.16 * inst/include/spdlog/*: New upstream release spdlog 1.13.0","title":"2024"},{"location":"changelog/#2023","text":"2023-11-29 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.15 * src/RcppExports.cpp: Regenerated under updated Rcpp to address format string issue reported by R-devel * man/RcppSpdlog-package.Rd: Remove some empty default entries 2023-07-09 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.14 2023-07-08 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdlog/*: New upstream release spdlog 1.12.0 2023-06-28 Dirk Eddelbuettel edd@debian.org * README.md: Add r-universe badge 2023-06-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.13 2023-06-13 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp (log_init): Add a simple convenience wrapper to log_setup() which omits the first 'logger name' argument * inst/include/spdl.h: Define convenience wrappers init() and log() 2023-03-19 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/Makevars: No longer set a C++ standard * R/RcppExports.R (setLoadAction): Updated .Call using backticks 2023-01-17 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog_stopwatch.h: Define stopwatch without fmt.h header * inst/include/RcppSpdlog_types.h: Use spdlog_stopwatch if #define set 2023-01-07 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.12","title":"2023"},{"location":"changelog/#2022","text":"2022-12-27 Dirk Eddelbuettel edd@debian.org * src/interface.cpp: Add documentation reference for format pattern * man/log_setup.Rd: Idem * R/RcppExports.R: Idem 2022-12-25 Dirk Eddelbuettel edd@debian.org * inst/include/spdl.h: Wrap three RcppSpdlog::*_stopwatch() functions 2022-12-23 Dirk Eddelbuettel edd@debian.org * src/interface.cpp: Split stopwatch documentation off * man/get_stopwatch.Rd: Idem * man/log_setup.Rd: Idem * src/RcppExports.cpp: Idem * R/RcppExports.R: Idem 2022-12-22 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp: Define and document three new functions for stopwatch * R/RcppExports.R: Export new functions * src/RcppExports.cpp: Idem * inst/include/RcppSpdlog_RcppExports.h: Idem * inst/include/RcppSpdlog_types.h: Include stopwatch, add XPtr template * inst/include/RcppSpdlog: Use new header * man/log_setup.Rd: Add documentation * R/stopwatch.R: Add two S3 methods for stopwatch objects * NAMESPACE: Export methods * inst/include/rcpp_sink.h: Use lighter Rcpp interface 2022-12-13 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.11 * vignettes/introduction.md: Microedit 2022-12-12 Dirk Eddelbuettel edd@debian.org * src/interface.cpp (log_filesetup): Setup (simple) file-based logger * R/RcppExports.R: R accessor * src/RcppExports.cpp: Autogenerated export for C level access * inst/include/RcppSpdlog_RcppExports.h: Idem * inst/include/rcpp_sink.h: Added #include * man/log_setup.Rd: Added documentation * inst/include/spdl.h: Added in spdl namespace 2022-12-02 Dirk Eddelbuettel edd@debian.org * README.md: Mention the new spdl package 2022-11-18 Dirk Eddelbuettel edd@debian.org * src/formatter.cpp: Export to C++ to make formatter() callable * src/RcppExports.cpp: Autogenerated export for C level access * inst/include/RcppSpdlog_RcppExports.h: Idem 2022-11-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.10 * vignettes/introduction.md: More edits 2022-11-15 Dirk Eddelbuettel edd@debian.org * src/formatter.cpp (formatter): Add formatting helper which passes logging string to fmt::format() enable fmt's \"format\" from R * src/RcppExports.cpp: Ditto * R/RcppExports.R (formatter): Ditto * man/formatter.Rd: Docs * inst/include/spdl.h: Include fmtlib::fmt via spdlog 2022-11-14 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdl.h: Use variadic templates to fmt::format 2022-11-04 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.9 2022-11-03 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdlog/*: New upstream release spdlog 1.11.0 * vignettes/introduction.md: Small edits 2022-11-02 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.md: New sections for access from R and C++ 2022-11-01 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/RcppSpdlog: Ad second shorter namespace 'spdl' with shorter (inlined) function names as simpler accessors * vignettes/introduction.md: Two new sections on access from R and C++, respectively 2022-10-31 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version 2022-10-30 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp: Add R interface to spdlog * man/log_setup.Rd: Documentation * .github/workflows/ci.yaml (jobs): Update to actions/checkout@v3 * src/interface.cpp: Activate R and C++ interface generation * R/RcppExports.R: Updated accordingly * src/RcppExports.cpp: Idem * inst/include/RcppSpdlog.h: Generated * inst/include/RcppSpdlog_RcppExports.h: Idem 2022-04-04 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.8 * inst/include/spdlog/*: New upstream release spdlog 1.10.0","title":"2022"},{"location":"changelog/#2021","text":"2021-12-05 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.7 2021-11-20 Dirk Eddelbuettel edd@debian.org * vignettes/water.css: Added css file 2021-11-19 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * vignettes/introduction.md: Converted from Rmd to simplermarkdown * DESCRIPTION: Switched VignetteBuilder: to simplermarkdown 2021-08-12 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * inst/include/spdlog/*: New upstream release spdlog 1.9.2 2021-07-27 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * inst/include/spdlog/*: New upstream release spdlog 1.9.1 2021-07-21 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.6 * inst/include/spdlog/*: New upstream spdlog 1.9.0 (with fmt 8.x) 2021-03-28 Dirk Eddelbuettel edd@debian.org * docs/mkdmt-src/: Moved mkdocs-material input 2021-03-27 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.5 2021-03-25 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: New upstream release spdlog 1.8.4 + 1.8.5 2021-03-24 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Description): Mention Gabi explicitly (URL): List GitHub repo and package pages (BugReports): List GitHub issues pages * inst/include/spdlog/*: New upstream release spdlog 1.8.3","title":"2021"},{"location":"changelog/#2020","text":"2020-12-25 Dirk Eddelbuettel edd@debian.org * .github/workflows/ci.yaml: Small tweaks to CI YAML file 2020-12-11 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.4 * inst/include/spdlog/*: New upstream release spdlog 1.8.2 * .github/workflows/ci.yaml: Add CI runner using r-ci 2020-10-23 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.3 * docs/: Added package website * docs-src/: Added package website inputs 2020-10-19 Dirk Eddelbuettel edd@debian.org * README.md: Updated example 2020-10-08 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.Rmd (vignette): Compile-time example added 2020-10-04 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.Rmd (vignette): New (draft) vignette * DESCRIPTION (VignetteBuilder): Add knitr (Suggests): Add knitr, rmarkdown, minidown * inst/examples/exampleTwo.cpp (exampleTwo): Added cleanup at end with logger removal to permit multiple calls to example function * inst/examples/exampleThree.cpp (exampleThree): Idem 2020-10-01 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: Upgraded to upstream release 1.8.1 2020-09-30 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp (exampleRsink): Use default logger instance 2020-09-29 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp (setLogLevel): New function * R/RcppExports.R (exampleRsink): R accessor * man/setLogLevel.Rd: Documentation 2020-09-28 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/logger-inl.h: Synchronised with our PR #1685 switching to REprintf() if R_R_H and USING_R defined * inst/include/RcppSpdlog: Include R.h so that R_R_H and USING_R defined, define SPDLOG_DISABLE_DEFAULT_LOGGER here * src/exampleRsink.cpp: Removed SPDLOG_DISABLE_DEFAULT_LOGGER def. 2020-09-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.2 * inst/include/spdlog/*: Upgraded to upstream release 1.8.0 * inst/include/spdlog/logger-inl.h: Switch to REprintf as before * .travis.yml: Use BSPM, turn os macOS * src/exampleRsink.cpp (exampleRsink): Add 'stopwatch' demo 2020-09-08 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.1 2020-08-21 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp: Renamed from exampleFour() * man/exampleRsink.Rd: Idem * src/RcppExports.cpp: Updated * R/RcppExports.R: Idem * README.md: Some more edits 2020-08-20 Dirk Eddelbuettel edd@debian.org * inst/include/RcppSpdlog: Easy wrapper for spdlog and R sink * inst/include/rcpp_sink.h: A sink for R using Rcpp::Rcout * src/exampleFour.cpp: Rewritten and now R CMD check clean * inst/examples/examplesFour.cpp: Now in src/, R sink in its header * README.md: Edited, added two badges * cleanup: Added * .editorconfig: Idem 2020-08-19 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: Using spdlog version 1.7 * inst/examples/*: Four simple usage examples * .travis.yml: Added though no real tests present * src/exampleFour.cpp (exampleFour): Simple wrapper around simple Rcpp logger class which still triggers R warnings * man/exampleFour.Rd: Basic help page * src/RcppExports.cpp: Generated * src/Makevars: Added * R/RcppExports.R: Idem * NAMESPACE: Added * DESCRIPTION: Added Imports: and LinkingTo: for Rcpp","title":"2020"},{"location":"news/","text":"News for Package RcppSpdlog Version 0.0.16 (2024-01-12) Upgraded to upstream releases spdlog 1.13.0 Version 0.0.15 (2023-11-29) Correct default package help page slighly RcppExports.cpp has been regenerated under an updated Rcpp to address a format string warning under R-devel Version 0.0.14 (2023-07-09) Added new badge to README.md Upgraded to upstream releases spdlog 1.12.0 Version 0.0.13 (2023-06-17) Minor tweak to stopwatch setup avoids pulling in fmt No longer set a C++ compilation standard as the default choices by R are sufficient for the package Add convenience wrapper log_init omitting first argument to log_setup while preserving the interface from the latter Add convenience setup wrappers init and log to API header file spdl.h Version 0.0.12 (2023-01-07) Addeed support for 'stopwatch' object allowing for simple timing (from both C++ and R) via the logging framework. The \u2018spdlog\u2019 logging pattern is documented via a reference. Version 0.0.11 (2022-12-13) Export the formatter at C level Mention package spdl in README.md Support simple file-based logger Version 0.0.10 (2022-11-17) Support variadic templates with fmt::format Add R formatting helper which converts arguments to character taking advantage of variadic template logger: fmt logging from R Expand vignette Version 0.0.9 (2022-11-04) Add both an R and an C++ interface to spdlog Update GitHub Actions to checkout@v3 Add a shorter aliased namespace for C++ Upgraded to upstream releases spdlog 1.11.0 Version 0.0.8 (2022-04-04) Upgraded to upstream releases spdlog 1.10.0 Version 0.0.7 (2021-12-05) Upgraded to upstream bug fix releases spdlog 1.9.1 and 1.9.2 Travis artifacts and badges have been pruned Vignette now uses simplermarkdown Version 0.0.6 (2021-07-21) Upgraded to upstream release spdlog 1.9.0 Version 0.0.5 (2020-12-11) Upgraded to upstream release spdlog 1.8.5 (and 1.8.4 and 1.8.3) Small enhancements to DESCRIPTION files Version 0.0.4 (2020-12-11) Upgraded to upstream release spdlog 1.8.2 Added GitHub Actions CI using run.sh from r-ci Version 0.0.3 (2020-10-23) New function setLogLevel with R accessor in exampleRsink example Updated exampleRsink to use default logger instance Upgraded to upstream release 1.8.1 which contains finalised upstream use to switch to REprintf() if R compilation detected Added new vignette with extensive usage examples, added compile-time logging switch example A package documentation website was added Version 0.0.2 (2020-09-17) Upgraded to upstream release 1.8.0 Switched Travis CI to using BSPM, also test on macOS Added 'stopwatch' use to main R sink example Version 0.0.1 (2020-09-08) Initial release with added R/Rcpp logging sink example","title":"News"},{"location":"man/RcppSpdlog-package/","text":"R and C++ Interfaces to 'spdlog' C++ Header Library for Logging Description The mature and widely-used C++ logging library 'spdlog' by Gabi Melman provides many desirable features. This package bundles these header files for easy use by R packages from both their R and C or C++ code. Explicit use via 'LinkingTo:' is also supported. Also see the 'spdl' package which enhanced this package with a consistent R and C++ interface. Details The DESCRIPTION file: This package was not yet installed at build time. Index: This package was not yet installed at build time. This section should provide a more detailed overview of how to use the package, including the most important functions. Author(s) Dirk Eddelbuettel Maintainer: Dirk Eddelbuettel \\ References This optional section can contain literature or other references for background information. See Also Optional links to other man pages Examples ## Optional simple examples of the most important functions ## Use \\dontrun{} around code to be shown but not executed","title":"RcppSpdlog package"},{"location":"man/RcppSpdlog-package/#r-and-c-interfaces-to-spdlog-c-header-library-for-logging","text":"","title":"R and C++ Interfaces to 'spdlog' C++ Header Library for Logging"},{"location":"man/RcppSpdlog-package/#description","text":"The mature and widely-used C++ logging library 'spdlog' by Gabi Melman provides many desirable features. This package bundles these header files for easy use by R packages from both their R and C or C++ code. Explicit use via 'LinkingTo:' is also supported. Also see the 'spdl' package which enhanced this package with a consistent R and C++ interface.","title":"Description"},{"location":"man/RcppSpdlog-package/#details","text":"The DESCRIPTION file: This package was not yet installed at build time. Index: This package was not yet installed at build time. This section should provide a more detailed overview of how to use the package, including the most important functions.","title":"Details"},{"location":"man/RcppSpdlog-package/#authors","text":"Dirk Eddelbuettel Maintainer: Dirk Eddelbuettel \\","title":"Author(s)"},{"location":"man/RcppSpdlog-package/#references","text":"This optional section can contain literature or other references for background information.","title":"References"},{"location":"man/RcppSpdlog-package/#see-also","text":"Optional links to other man pages","title":"See Also"},{"location":"man/RcppSpdlog-package/#examples","text":"## Optional simple examples of the most important functions ## Use \\dontrun{} around code to be shown but not executed","title":"Examples"},{"location":"man/exampleRsink/","text":"spdlog Example using a sink for R Description A simple example invoking a derived R/Rcpp logger. Also demonstrates the stopwatch feature. For more features see the 'spdlog' documnetation. Usage exampleRsink() Details Note that this no longer triggers R warnings thanks to excellent help by Gabi Melman. Value None Examples exampleRsink()","title":"exampleRsink"},{"location":"man/exampleRsink/#spdlog-example-using-a-sink-for-r","text":"","title":"spdlog Example using a sink for R"},{"location":"man/exampleRsink/#description","text":"A simple example invoking a derived R/Rcpp logger. Also demonstrates the stopwatch feature. For more features see the 'spdlog' documnetation.","title":"Description"},{"location":"man/exampleRsink/#usage","text":"exampleRsink()","title":"Usage"},{"location":"man/exampleRsink/#details","text":"Note that this no longer triggers R warnings thanks to excellent help by Gabi Melman.","title":"Details"},{"location":"man/exampleRsink/#value","text":"None","title":"Value"},{"location":"man/exampleRsink/#examples","text":"exampleRsink()","title":"Examples"},{"location":"man/formatter/","text":"Simple Pass-Through Formatter to fmt::format() Description The C-level interface of R does not make it easy to pass ... arguments. This helper function assumes it has already been called with format() on each argument (as a wrapper can do) so it just spreads out the class to fmt::format{} which, being C++, uses variadic templates to receive the arguments. The main motivation for this function to able to format string as use by the \u2018fmtlib::fmt\u2019 library included in \u2018spdlog\u2019 to write similar debug strings in both R and C++. This function permits R calls with multiple arguments of different types which (by being formatted on the R side) are handled as strings (whereas C++ logging has access to the templating logic). Usage formatter(s, v) Arguments s A character variable with a format string for \u2018fmtlib::fmt\u2019 v A character vector with the logging string arguments. Value A single (formatted) string See Also https://github.com/fmtlib/fmt","title":"Formatter"},{"location":"man/formatter/#simple-pass-through-formatter-to-fmtformat","text":"","title":"Simple Pass-Through Formatter to fmt::format()"},{"location":"man/formatter/#description","text":"The C-level interface of R does not make it easy to pass ... arguments. This helper function assumes it has already been called with format() on each argument (as a wrapper can do) so it just spreads out the class to fmt::format{} which, being C++, uses variadic templates to receive the arguments. The main motivation for this function to able to format string as use by the \u2018fmtlib::fmt\u2019 library included in \u2018spdlog\u2019 to write similar debug strings in both R and C++. This function permits R calls with multiple arguments of different types which (by being formatted on the R side) are handled as strings (whereas C++ logging has access to the templating logic).","title":"Description"},{"location":"man/formatter/#usage","text":"formatter(s, v)","title":"Usage"},{"location":"man/formatter/#arguments","text":"s A character variable with a format string for \u2018fmtlib::fmt\u2019 v A character vector with the logging string arguments.","title":"Arguments"},{"location":"man/formatter/#value","text":"A single (formatted) string","title":"Value"},{"location":"man/formatter/#see-also","text":"https://github.com/fmtlib/fmt","title":"See Also"},{"location":"man/get_stopwatch/","text":"R Accessor Functions for spdlog Stopwatch Description A set of functions provides access to the spdlog stopwatch facilty. As stopwatch object is a simple container around a C++ std::chrono object which (essentially) reports elapsed-time since creation. The object is exported to R via an external pointer permitting use from both R and C++. Usage get_stopwatch() elapsed_stopwatch(sw) format_stopwatch(sw) ## S3 method for class 'stopwatch' print(x, ...) ## S3 method for class 'stopwatch' format(x, ...) Arguments sw An S3 object of type stopwatch . x An S3 object of type stopwatch . ... Dotted argument required by generic, unused here. Details Several functions are provided: get_stopwatch Returns a stopwatch object (as an S3 object). elapsed_stopwatch Returns elapsed time for stopwatch in seconds. format_stopwatch Returns elapsed time for stopwatch as character variable. The stopwatch object has print and format methods. Value The desired object is returned: respectively, a stopwatch object as an external pointer in an S3 class, the elapsed time in seconds as a double, or formatted as a character variable. Examples w <- get_stopwatch() Sys.sleep(0.2) elapsed_stopwatch(w) format_stopwatch(w)","title":"Get stopwatch"},{"location":"man/get_stopwatch/#r-accessor-functions-for-spdlog-stopwatch","text":"","title":"R Accessor Functions for spdlog Stopwatch"},{"location":"man/get_stopwatch/#description","text":"A set of functions provides access to the spdlog stopwatch facilty. As stopwatch object is a simple container around a C++ std::chrono object which (essentially) reports elapsed-time since creation. The object is exported to R via an external pointer permitting use from both R and C++.","title":"Description"},{"location":"man/get_stopwatch/#usage","text":"get_stopwatch() elapsed_stopwatch(sw) format_stopwatch(sw) ## S3 method for class 'stopwatch' print(x, ...) ## S3 method for class 'stopwatch' format(x, ...)","title":"Usage"},{"location":"man/get_stopwatch/#arguments","text":"sw An S3 object of type stopwatch . x An S3 object of type stopwatch . ... Dotted argument required by generic, unused here.","title":"Arguments"},{"location":"man/get_stopwatch/#details","text":"Several functions are provided: get_stopwatch Returns a stopwatch object (as an S3 object). elapsed_stopwatch Returns elapsed time for stopwatch in seconds. format_stopwatch Returns elapsed time for stopwatch as character variable. The stopwatch object has print and format methods.","title":"Details"},{"location":"man/get_stopwatch/#value","text":"The desired object is returned: respectively, a stopwatch object as an external pointer in an S3 class, the elapsed time in seconds as a double, or formatted as a character variable.","title":"Value"},{"location":"man/get_stopwatch/#examples","text":"w <- get_stopwatch() Sys.sleep(0.2) elapsed_stopwatch(w) format_stopwatch(w)","title":"Examples"},{"location":"man/log_setup/","text":"R Accessor Functions for spdlog Logger Description Several R-level functions can access the spdlog logging facilties. As spdlog is a C++-level logging library, these are R function permit concurrent logging from both R and C++. Usage log_setup(name = \"default\", level = \"warn\") log_init(level = \"warn\") log_filesetup(filename, name = \"default\", level = \"warn\") log_drop(name) log_set_pattern(s) log_set_level(s) log_trace(s) log_debug(s) log_info(s) log_warn(s) log_error(s) log_critical(s) Arguments name A character variable with the logging instance name, default value is \u2018default\u2019. level A character variable with the default logging level, default value is \u2018warn\u2019. filename A character variable with the logging filename if a file-based logger is instantiated. s A character variable with the logging pattern, level or message. Details Several functions are provided: log_setup Initializes a logger (which becomes the default logger). log_filesetup Initializes a file-based logger (which becomes the default). log_drop Removes logger (which in general should not be needed). log_set_pattern Changes the default logging message pattern. log_set_level Sets the logging level threshold. log_trace Logs a trace-level message. log_debug Logs a debug-level message. log_info Logs a info-level message. log_warn Logs a warn-level message. log_error Logs a error-level message. log_critical Logs a critical-level message. Supported logging levels are, in order of increasing threshold values, \u2018trace\u2019, \u2018debug\u2019, \u2018warn\u2019, \u2018info\u2019, \u2018warn\u2019, \u2018error\u2019, and \u2018critical\u2019. A message issued below the current threshold is not displayed whereas a message at or above the current threshold is displayed. The default level is \u2018warn\u2019. Value Nothing is returned from these functions as they are invoked for their side-effects. See Also The logging pattern format is described in at the repo in the page https://github.com/gabime/spdlog/wiki/3.-Custom-formatting . Examples log_setup(\"demo\") # at default level 'warn' log_info(\"this message is NOT seen\") log_set_level(\"debug\") log_info(\"this message is seen\") log_warn(\"as is this message\")","title":"Log setup"},{"location":"man/log_setup/#r-accessor-functions-for-spdlog-logger","text":"","title":"R Accessor Functions for spdlog Logger"},{"location":"man/log_setup/#description","text":"Several R-level functions can access the spdlog logging facilties. As spdlog is a C++-level logging library, these are R function permit concurrent logging from both R and C++.","title":"Description"},{"location":"man/log_setup/#usage","text":"log_setup(name = \"default\", level = \"warn\") log_init(level = \"warn\") log_filesetup(filename, name = \"default\", level = \"warn\") log_drop(name) log_set_pattern(s) log_set_level(s) log_trace(s) log_debug(s) log_info(s) log_warn(s) log_error(s) log_critical(s)","title":"Usage"},{"location":"man/log_setup/#arguments","text":"name A character variable with the logging instance name, default value is \u2018default\u2019. level A character variable with the default logging level, default value is \u2018warn\u2019. filename A character variable with the logging filename if a file-based logger is instantiated. s A character variable with the logging pattern, level or message.","title":"Arguments"},{"location":"man/log_setup/#details","text":"Several functions are provided: log_setup Initializes a logger (which becomes the default logger). log_filesetup Initializes a file-based logger (which becomes the default). log_drop Removes logger (which in general should not be needed). log_set_pattern Changes the default logging message pattern. log_set_level Sets the logging level threshold. log_trace Logs a trace-level message. log_debug Logs a debug-level message. log_info Logs a info-level message. log_warn Logs a warn-level message. log_error Logs a error-level message. log_critical Logs a critical-level message. Supported logging levels are, in order of increasing threshold values, \u2018trace\u2019, \u2018debug\u2019, \u2018warn\u2019, \u2018info\u2019, \u2018warn\u2019, \u2018error\u2019, and \u2018critical\u2019. A message issued below the current threshold is not displayed whereas a message at or above the current threshold is displayed. The default level is \u2018warn\u2019.","title":"Details"},{"location":"man/log_setup/#value","text":"Nothing is returned from these functions as they are invoked for their side-effects.","title":"Value"},{"location":"man/log_setup/#see-also","text":"The logging pattern format is described in at the repo in the page https://github.com/gabime/spdlog/wiki/3.-Custom-formatting .","title":"See Also"},{"location":"man/log_setup/#examples","text":"log_setup(\"demo\") # at default level 'warn' log_info(\"this message is NOT seen\") log_set_level(\"debug\") log_info(\"this message is seen\") log_warn(\"as is this message\")","title":"Examples"},{"location":"man/setLogLevel/","text":"spdlog Logging Lever Setter Description A helper function to turn a logging level given as string into the current logging level Usage setLogLevel(name) Arguments name A string with the logging level. Value understood are, in decreasing verbosity \u2018trace\u2019, \u2018debug\u2019, \u2018info\u2019, \u2018warning\u2019, \u2018error\u2019, \u2018critical\u2019, and \u2018off\u2019. Unrecognised names are equivalent to \u2018off\u2019. Value Nothing is returned.","title":"setLogLevel"},{"location":"man/setLogLevel/#spdlog-logging-lever-setter","text":"","title":"spdlog Logging Lever Setter"},{"location":"man/setLogLevel/#description","text":"A helper function to turn a logging level given as string into the current logging level","title":"Description"},{"location":"man/setLogLevel/#usage","text":"setLogLevel(name)","title":"Usage"},{"location":"man/setLogLevel/#arguments","text":"name A string with the logging level. Value understood are, in decreasing verbosity \u2018trace\u2019, \u2018debug\u2019, \u2018info\u2019, \u2018warning\u2019, \u2018error\u2019, \u2018critical\u2019, and \u2018off\u2019. Unrecognised names are equivalent to \u2018off\u2019.","title":"Arguments"},{"location":"man/setLogLevel/#value","text":"Nothing is returned.","title":"Value"},{"location":"vignette/introduction/","text":"Introducing RcppSpdlog spdlog is a widely-used and very capable header-only C++ library for logging. The RcppSpdlog package provides R users with easy-to-use customized access to the spdlog logging library by including its headers in an R package which permit other R packages to deploy it via a simple LinkingTo: RcppSpdlog as described in Section 1.1.3 of WRE . spdlog is mature and widely deployed. It also has a very rich set of features described at the repository wiki . This vignette will highlight a few first use cases. Note that in order to use RcppSpdlog in an R package that might get distributed to CRAN , the code should follow the example R and C++ code in function exampleRsink() as described below. We will however start with some simpler examples. Do not copy those into your R package. The package checks used by R test for use of stdout and stderr which is why the customized setup described later is preferable. Initial example: Basics This example follows the simplest and initial example in the spdlog . It is also included in the RcppSpdlog package as examples/exampleOne.cpp . As discussed above, do not use this example as a starting point in an R package. // based on the 'basic usage' example in the README.md at https://github.com/gabime/spdlog #include \"spdlog/spdlog.h\" #include // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleOne() { // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%L] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug(\"This message should be displayed..\"); // Compile time log levels // define SPDLOG_ACTIVE_LEVEL to desired level SPDLOG_TRACE(\"Some trace message with param {}\", {}); SPDLOG_DEBUG(\"Some debug message\"); } /*** R exampleOne() */ When built, which is easiest via Rcpp::sourceCpp() , the final block ensures that the created function exampleOne() is executed. In one previous run, the following output was produded: R> exampleOne() [14:25:03.362024] [I] [thread 2453030] Welcome to spdlog! [14:25:03.362047] [E] [thread 2453030] Some error message with arg: 1 [14:25:03.362051] [W] [thread 2453030] Easy padding in numbers like 00000012 [14:25:03.362053] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [14:25:03.362056] [I] [thread 2453030] Support for floats 1.23 [14:25:03.362058] [I] [thread 2453030] Positional args are supported too.. [14:25:03.362060] [I] [thread 2453030] left aligned [14:25:03.362061] [D] [thread 2453030] This message should be displayed.. R> We note the easy-to-formatting in the source which benefits from the embedded fmt package for easy-to-use variable expansion. We also notice the different logging \"levels\" indicated by single letters: info , errror , warning , critical and debug . More on this below. Second example: Showcase This second example follows a more complete example in the spdlog documention and highlights numerous features of the library. As before, this example is also included in the RcppSpdlog package as examples/exampleTwo.cpp . And as before, do not use this example as a starting point in an R package. #include \"spdlog/spdlog.h\" #include void stdout_logger_example(); void basic_example(); void rotating_example(); void daily_example(); void async_example(); void binary_example(); void trace_example(); void multi_sink_example(); void user_defined_example(); void err_handler_example(); void syslog_example(); void clone_example(); #include \"spdlog/spdlog.h\" // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleTwo() { spdlog::info(\"Welcome to spdlog version {}.{}.{} !\", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:>8} aligned, {:<8} aligned\", \"right\", \"left\"); // Runtime log levels spdlog::set_level(spdlog::level::info); // Set global log level to info spdlog::debug(\"This message should not be displayed!\"); spdlog::set_level(spdlog::level::trace); // Set specific logger's log level spdlog::debug(\"This message should be displayed..\"); // Customize msg format for all loggers spdlog::set_pattern(\"[%H:%M:%S %z] [%^%L%$] [thread %t] %v\"); spdlog::info(\"This an info message with custom format\"); spdlog::set_pattern(\"%+\"); // back to default format try { stdout_logger_example(); basic_example(); rotating_example(); daily_example(); clone_example(); async_example(); binary_example(); multi_sink_example(); user_defined_example(); err_handler_example(); trace_example(); // Flush all *registered* loggers using a worker thread every 3 seconds. // note: registered loggers *must* be thread safe for this to work correctly! spdlog::flush_every(std::chrono::seconds(3)); // Apply some function on all registered loggers spdlog::apply_all([&](std::shared_ptr l) { l->info(\"End of example.\"); }); // Release all spdlog resources, and drop all loggers in the registry. // This is optional (only mandatory if using windows + async log). //spdlog::shutdown(); } // Exceptions will only be thrown upon failed logger or sink construction (not during logging). catch (const spdlog::spdlog_ex &ex) { std::printf(\"Log initialization failed: %s\\n\", ex.what()); return; } // added to this example file allow multiple runs of function spdlog::drop(\"console\"); spdlog::drop(\"file_logger\"); spdlog::drop(\"some_logger_name\"); spdlog::drop(\"daily_logger\"); spdlog::drop(\"async_file_logger\"); } #include \"spdlog/sinks/stdout_color_sinks.h\" // or #include \"spdlog/sinks/stdout_sinks.h\" if no colors needed. void stdout_logger_example() { // Create color multi threaded logger. auto console = spdlog::stdout_color_mt(\"console\"); // or for stderr: // auto console = spdlog::stderr_color_mt(\"error-logger\"); } #include \"spdlog/sinks/basic_file_sink.h\" void basic_example() { // Create basic file logger (not rotated). auto my_logger = spdlog::basic_logger_mt(\"file_logger\", \"logs/basic-log.txt\"); } #include \"spdlog/sinks/rotating_file_sink.h\" void rotating_example() { // Create a file rotating logger with 5mb size max and 3 rotated files. auto rotating_logger = spdlog::rotating_logger_mt(\"some_logger_name\", \"logs/rotating.txt\", 1048576 * 5, 3); } #include \"spdlog/sinks/daily_file_sink.h\" void daily_example() { // Create a daily logger - a new file is created every day on 2:30am. auto daily_logger = spdlog::daily_logger_mt(\"daily_logger\", \"logs/daily.txt\", 2, 30); } // Clone a logger and give it new name. // Useful for creating component/subsystem loggers from some \"root\" logger. void clone_example() { auto network_logger = spdlog::default_logger()->clone(\"network\"); network_logger->info(\"Logging network stuff..\"); } #include \"spdlog/async.h\" void async_example() { // Default thread pool settings can be modified *before* creating the async logger: // spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread. auto async_file = spdlog::basic_logger_mt(\"async_file_logger\", \"logs/async_log.txt\"); // alternatively: // auto async_file = // spdlog::create_async(\"async_file_logger\", // \"logs/async_log.txt\"); for (int i = 1; i < 101; ++i) { async_file->info(\"Async message #{}\", i); } } // Log binary data as hex. // Many types of std::container types can be used. // Iterator ranges are supported too. // Format flags: // {:X} - print in uppercase. // {:s} - don't separate each byte with space. // {:p} - don't print the position on each line start. // {:n} - don't split the output to lines. #include \"spdlog/fmt/bin_to_hex.h\" void binary_example() { std::vector buf; for (int i = 0; i < 80; i++) { buf.push_back(static_cast(i & 0xff)); } spdlog::info(\"Binary example: {}\", spdlog::to_hex(buf)); spdlog::info(\"Another binary example:{:n}\", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10)); // more examples: // logger->info(\"uppercase: {:X}\", spdlog::to_hex(buf)); // logger->info(\"uppercase, no delimiters: {:Xs}\", spdlog::to_hex(buf)); // logger->info(\"uppercase, no delimiters, no position info: {:Xsp}\", spdlog::to_hex(buf)); } // Compile time log levels. // define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE) void trace_example() { // trace from default logger SPDLOG_TRACE(\"Some trace message.. {} ,{}\", 1, 3.23); // debug from default logger SPDLOG_DEBUG(\"Some debug message.. {} ,{}\", 1, 3.23); // trace from logger object auto logger = spdlog::get(\"file_logger\"); SPDLOG_LOGGER_TRACE(logger, \"another trace message\"); } // A logger with multiple sinks (stdout and file) - each with a different format and log level. void multi_sink_example() { auto console_sink = std::make_shared(); console_sink->set_level(spdlog::level::warn); console_sink->set_pattern(\"[multi_sink_example] [%^%l%$] %v\"); auto file_sink = std::make_shared(\"logs/multisink.txt\", true); file_sink->set_level(spdlog::level::trace); spdlog::logger logger(\"multi_sink\", {console_sink, file_sink}); logger.set_level(spdlog::level::debug); logger.warn(\"this should appear in both console and file\"); logger.info(\"this message should not appear in the console, only in the file\"); } // User defined types logging by implementing operator<< #include \"spdlog/fmt/ostr.h\" // must be included struct my_type { int i; template friend OStream &operator<<(OStream &os, const my_type &c) { return os << \"[my_type i=\" << c.i << \"]\"; } }; void user_defined_example() { spdlog::info(\"user defined type: {}\", my_type{14}); } // Custom error handler. Will be triggered on log failure. void err_handler_example() { // can be set globally or per logger(logger->set_error_handler(..)) spdlog::set_error_handler([](const std::string &msg) { printf(\"*** Custom log error handler: %s ***\\n\", msg.c_str()); }); } // syslog example (linux/osx/freebsd) #ifndef _WIN32 #include \"spdlog/sinks/syslog_sink.h\" void syslog_example() { std::string ident = \"spdlog-example\"; auto syslog_logger = spdlog::syslog_logger_mt(\"syslog\", ident, LOG_PID); syslog_logger->warn(\"This is warning that will end up in syslog.\"); } #endif // Android example. #if defined(__ANDROID__) #include \"spdlog/sinks/android_sink.h\" void android_example() { std::string tag = \"spdlog-android\"; auto android_logger = spdlog::android_logger_mt(\"android\", tag); android_logger->critical(\"Use \\\"adb shell logcat\\\" to view this message.\"); } #endif /*** R exampleTwo() */ We are not showing the output here; it can be compiled, linked, loaded and run just as above by simply passing the filename to Rcpp::sourceCpp() . Note that is will create a few demonstration logfiles so you may want to run the example from a temporary directory. Third example: Colour The next example highlights a colour 'sink' for the logger. Again, do not use this as a starting point for your package as R CMD check will protest about use of stdout . #include \"spdlog/spdlog.h\" #include \"spdlog/sinks/stdout_color_sinks.h\" #include // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleThree() { auto console = spdlog::stdout_color_mt(\"console\"); // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%^%L%$] [thread %t] %v\"); spdlog::info(\"This an info message with custom format\"); //spdlog::set_pattern(\"%+\"); // back to default format spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); // added to this example file allow multiple runs of different package functions spdlog::drop(\"console\"); } /*** R exampleThree() */ When running this example in a terminal capable of displaying colour escape sequence, the logging levels are distinguished by colour. This ranges from green (\"info\") to yellow (\"warning\") to red (\"error\") and white-on-red (\"critical\"). Not that in this vignette color from standard output does how not show (in the keep-it-simple-mode we are using here). R> exampleThree() [14:47:52.260692] [I] [thread 2502026] This an info message with custom format [14:47:52.260715] [I] [thread 2502026] Welcome to spdlog! [14:47:52.260732] [E] [thread 2502026] Some error message with arg: 1 [14:47:52.260734] [W] [thread 2502026] Easy padding in numbers like 00000012 [14:47:52.260736] [C] [thread 2502026] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [14:47:52.260739] [I] [thread 2502026] Support for floats 1.23 [14:47:52.260741] [I] [thread 2502026] Positional args are supported too.. [14:47:52.260743] [I] [thread 2502026] left aligned R> Fourth Example: Dedicated R Logger The next example is suitable for use in R packages, and in fact included as an example in the package. We include the source file src/exampleRsink.cpp . // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include #include // also support stopwatch feature //' spdlog Example using a sink for R //' //' A simple example invoking a derived R/Rcpp logger. Also demonstrates the //' stopwatch feature. For more features see the 'spdlog' documnetation. //' //' Note that this no longer triggers R warnings thanks to excellent help by //' Gabi Melman. //' @return None //' @examples //' exampleRsink() // [[Rcpp::export]] void exampleRsink() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed spdlog::set_default_logger(sp); // and set as default spdlog::stopwatch sw; // instantiate a stop watch // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::info(\"Elapsed time: {}\", sw); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::info(\"Elapsed time: {}\", sw); } //' spdlog Logging Lever Setter //' //' A helper function to turn a logging level given as string //' into the current logging level //' //' @param name A string with the logging level. Value understood are, //' in decreasing verbosity \\sQuote{trace}, \\sQuote{debug}, \\sQuote{info}, //' \\sQuote{warning}, \\sQuote{error}, \\sQuote{critical}, and \\sQuote{off}. //' Unrecognised names are equivalent to \\sQuote{off}. //' @return Nothing is returned. // [[Rcpp::export]] void setLogLevel(const std::string &name) { spdlog::set_level(spdlog::level::from_str(name)); } The example file contains three key aspects to highlight: - use of the r_sink_mt() class for R-specific logger sink - use of the very convenient stopwatch object - use of logging levels We highlight these below after first showing the relevant output: R> exampleRsink() [16:52:12.076751] [fromR] [I] [thread 2453030] Welcome to spdlog! [16:52:12.076809] [fromR] [E] [thread 2453030] Some error message with arg: 1 [16:52:12.076823] [fromR] [I] [thread 2453030] Elapsed time: 9.6104e-05 [16:52:12.076833] [fromR] [W] [thread 2453030] Easy padding in numbers like 00000012 [16:52:12.076844] [fromR] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [16:52:12.076853] [fromR] [I] [thread 2453030] Support for floats 1.23 [16:52:12.076871] [fromR] [I] [thread 2453030] Positional args are supported too.. [16:52:12.076879] [fromR] [I] [thread 2453030] left aligned [16:52:12.076892] [fromR] [I] [thread 2453030] Elapsed time: 0.000167057 R> R-specific sink spdlog has the ability to derive and sub-class sinks for logger. The RcppSpdlog package uses this feature to implement a sink using the Rcpp conduit Rcpp::Rcout instead of std::cout as it conveniently redirects to the R output stream. This class should be the default one for any R packages wanting to use spdlog while also passing R CMD check . A second important aspect of the initial code in function exampleRsink() is how a named logging instance is requested. If none is found, a new one is instantiated. Next, this logger is made the default logger permitting convenient programmatic access via spdlog:: . Stopwatch A powerful (recent) feature of the include fmt library is the automatic formatting of timestamps and interval. As the code example shows, simply instantianting an object, here called sw , and referring to it later is all that takes. Log-Level A second utility function setLogLevel() is also provided. Usage is simple: after calling it with a given level, only message equal to it or higher are shown as the next example shows. R> setLogLevel(\"error\") R> exampleRsink() [16:54:12.666261] [fromR] [E] [thread 2453030] Some error message with arg: 1 [16:54:12.666286] [fromR] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 R> By requestion level 'error', message of level 'info', 'warning' or 'debug' are suppressed but messages levels 'error' or 'critical' as shown as desired. Fifth Example: Initialization Package desiring to use RcppSpdlog can initialize its facilities during startup. For that we first define a setup function // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include //' Set a new default logger for R //' // [[Rcpp::export]] void setDefault() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed sp->set_pattern(\"[%H:%M:%S.%f] [%^%L%$] %v\"); spdlog::set_default_logger(sp); } We can then call this function during startup: .onLoad <- function(libname, pkgname) { setDefault(); } Sixth Example: Compile-time Selection Of course, spdlog also supports a common usage paradigm with loggers in which the decision of whether to log or not is compile-time rather than run time. As this is typically implemented via macros, usage is via upper-case macros as well. The following example shows a function with three different logging-level statements as well as a #define set such one and only one is shown. Similarly, code can contain debug or trace or info or ... statements which would not appear in the actually loaded \"production code\" (or CRAN version) if the compile-time logging level define is set high enough. // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include // A define such as this could also be set in src/Makevars via a -D flag #define SPDLOG_LOG_LEVEL SPDLOG_LEVEL_CRITICAL // [[Rcpp::export]] void demoInvisible() { Rcpp::Rcout << \"Hello from demoInvisible, just to show we're being called...\\n\"; // trace message via default logger SPDLOG_TRACE(\"Some trace message.. {} ,{}\", 1, 3.23); // debug message via default logger SPDLOG_DEBUG(\"Some debug message.. {} ,{}\", 1, 3.23); // debug message via default logger SPDLOG_CRITICAL(\"Some critical message.. {} ,{}\", 1, 3.23); } When a piece of code with such compile-time defines is used, we see the expected outcome. The following example uses default logger, and as the preceding section showed this can be set up to be the custom R sink: R> Rcpp::sourceCpp(\"/tmp/rcppspdlog.cpp\") # plus a '// [[Rcpp:depends(\"RcppSpdlog\")' R> demoInvisible() Hello from demoInvisible, just to show we're being called... [08:44:48.198075] [fromR] [C] [thread 2453030] Some critical message.. 1 ,3.23 R> Seventh Example: Access From R As of package 0.0.9, RcppSpdlog supports two new modes. The first is direct logging support from R and described in this section; the second is access from another R package and described thereafter. A number of basic functions are exported using Rcpp. These include log_setup(name, level) to instantiate a named logger at a given level (instead of an unnamed default at level 'warn'), log_filesetup(filename, name, level) (same using the named file as logging destination), a helper log_drop(name) to drop a named logger, two setters log_set_pattern() and log_set_level() to set, respectively, the displayed log pattern and the level. This is complemented by the actual loggers ranging from log_trace() and log_debug() to log_info() , log_warn() , log_error() and finally log_critical() . The following example (also the example in the manual page) illustrates. > library(RcppSpdlog) > log_setup(\"demo\") # default level 'warn' is used > log_info(\"this message is NOT seen\") > log_set_level(\"debug\") > log_set_pattern(\"%^[%H:%M:%S.%e] [%n] [%l] %v%$\") # set a pattern w/o process id > log_info(\"this message is seen\") [15:55:34.150] [demo] [info] this message is seen > log_warn(\"as is this message\") [ 15:55:37.513] [demo] [warning] as is this message > The interface expects a character value so use from either sprintf() or a string-interpolating helper such as glue::glue can be used: > log_info(sprintf(\"We can %s a %s with values %d\", \"build\", \"text\", 42L)) [16:03:37.728] [demo] [info] We can build a text with values 42 > log_info(glue::glue(\"We can {a} a {b} with values {v}\", a=\"build\", b=\"text\", v=42L)) [16:03:46.395] [demo] [info] We can build a text with values 42 > Eight Example: Access From Another R Package As of package 0.0.9, another package can use the C++ level functions (either with or without the R functions) by importing the RcppSpdlog while ensuring at least one function from the package is imported (so that the C-level interface functions are instantiated by R). This is time-honoured mechanism long-used by lme4 to access (compiled) functions from Matrix as well as by xts to access code from zoo , and others. To properly import the package, add just one import, for example importFrom((RcppSpdlog, log_setup) to the NAMESPACE file of your package, along with the required Imports: RcppSpdlog in the DESCRIPTION file. The available functions are the same as the ones described in the previous section, but now available at the C++ level in the RcppSpdlog namespace. So for example #include RcppSpdlog::log_setup(\"demoLogger\", \"info\"); // create logger at info level RcppSpdlog::log_info(\"logger created\"); will work. Nineth Example: More compact C++ Access As the (auto-generated, thanks to Rcpp ) interface described in the previous section is a little \"wordy\", we added a simple aliasing wrapping in a new namespace spdl and, given the protection from naming collisions offered by the namespace, shortened the accessor function names. So the previous example can also be used via #include spdl::setup(\"demoLogger\", \"info\"); // create logger at info level spdl::info(\"logger created\"); The logger interface takes a simple string. Two easy options exist for formatting such as string. First, one can rely on the tinyformat version included with Rcpp and use tfm::format() which works with standard printf() operators. Second, one can use the fmt library included with spdlog via an explicit call. # using tfm::format spdl::info(tfm::format(\"We %s values %d and %f\", \"log\", 42, 1.23)); # using fmt::format spdl::info(fmt::format(\"We {} values {} and {}\", \"log\", 42, 1.23)); Here both formatters have to be called explicitly as we use a simple one-function signature (per logging function) to the underlying C language implementation without the fuller flexibility of variadic arguments. As C++11 can be assumed, we can also offers a variadic template expansion for fmt::format() and the second example simply becomes spdl::info(\"We {} values {} and {}\", \"log\", 42, 1.23); Tenth Example: More compact R Access As the more compact access in the previous section is quite compelling we also created a sibbling R package spd providing a spdl namespace in R allowing _the exact same format strings too`. So spdl::info(\"We {} values {} and {}\", \"log\", 42L, 1.23); now also works from R using the same formatting string. We inted to upload spdl to CRAN too. Note that other all other formatting options are supported from R: the first argument is a character variable which can be constructed using paste , sprintf , or any of the string-interpolating packages. But as none of those methods works like fmt (which we have come to like a lot) we added support for it too. Conclusion spdlog and the included fmt are two very powerful and widely used C++ libraries. The RcppSpdlog package adds to them to the set of packages R users can deploy. The spd package makes access even easier and more consistent. It is our hope that the examples shown here are of interest to R users who are looking for effortless, performant and flexible logging solutions for their R packages.","title":"Introduction"},{"location":"vignette/introduction/#introducing-rcppspdlog","text":"spdlog is a widely-used and very capable header-only C++ library for logging. The RcppSpdlog package provides R users with easy-to-use customized access to the spdlog logging library by including its headers in an R package which permit other R packages to deploy it via a simple LinkingTo: RcppSpdlog as described in Section 1.1.3 of WRE . spdlog is mature and widely deployed. It also has a very rich set of features described at the repository wiki . This vignette will highlight a few first use cases. Note that in order to use RcppSpdlog in an R package that might get distributed to CRAN , the code should follow the example R and C++ code in function exampleRsink() as described below. We will however start with some simpler examples. Do not copy those into your R package. The package checks used by R test for use of stdout and stderr which is why the customized setup described later is preferable.","title":"Introducing RcppSpdlog"},{"location":"vignette/introduction/#initial-example-basics","text":"This example follows the simplest and initial example in the spdlog . It is also included in the RcppSpdlog package as examples/exampleOne.cpp . As discussed above, do not use this example as a starting point in an R package. // based on the 'basic usage' example in the README.md at https://github.com/gabime/spdlog #include \"spdlog/spdlog.h\" #include // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleOne() { // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%L] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug(\"This message should be displayed..\"); // Compile time log levels // define SPDLOG_ACTIVE_LEVEL to desired level SPDLOG_TRACE(\"Some trace message with param {}\", {}); SPDLOG_DEBUG(\"Some debug message\"); } /*** R exampleOne() */ When built, which is easiest via Rcpp::sourceCpp() , the final block ensures that the created function exampleOne() is executed. In one previous run, the following output was produded: R> exampleOne() [14:25:03.362024] [I] [thread 2453030] Welcome to spdlog! [14:25:03.362047] [E] [thread 2453030] Some error message with arg: 1 [14:25:03.362051] [W] [thread 2453030] Easy padding in numbers like 00000012 [14:25:03.362053] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [14:25:03.362056] [I] [thread 2453030] Support for floats 1.23 [14:25:03.362058] [I] [thread 2453030] Positional args are supported too.. [14:25:03.362060] [I] [thread 2453030] left aligned [14:25:03.362061] [D] [thread 2453030] This message should be displayed.. R> We note the easy-to-formatting in the source which benefits from the embedded fmt package for easy-to-use variable expansion. We also notice the different logging \"levels\" indicated by single letters: info , errror , warning , critical and debug . More on this below.","title":"Initial example: Basics"},{"location":"vignette/introduction/#second-example-showcase","text":"This second example follows a more complete example in the spdlog documention and highlights numerous features of the library. As before, this example is also included in the RcppSpdlog package as examples/exampleTwo.cpp . And as before, do not use this example as a starting point in an R package. #include \"spdlog/spdlog.h\" #include void stdout_logger_example(); void basic_example(); void rotating_example(); void daily_example(); void async_example(); void binary_example(); void trace_example(); void multi_sink_example(); void user_defined_example(); void err_handler_example(); void syslog_example(); void clone_example(); #include \"spdlog/spdlog.h\" // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleTwo() { spdlog::info(\"Welcome to spdlog version {}.{}.{} !\", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:>8} aligned, {:<8} aligned\", \"right\", \"left\"); // Runtime log levels spdlog::set_level(spdlog::level::info); // Set global log level to info spdlog::debug(\"This message should not be displayed!\"); spdlog::set_level(spdlog::level::trace); // Set specific logger's log level spdlog::debug(\"This message should be displayed..\"); // Customize msg format for all loggers spdlog::set_pattern(\"[%H:%M:%S %z] [%^%L%$] [thread %t] %v\"); spdlog::info(\"This an info message with custom format\"); spdlog::set_pattern(\"%+\"); // back to default format try { stdout_logger_example(); basic_example(); rotating_example(); daily_example(); clone_example(); async_example(); binary_example(); multi_sink_example(); user_defined_example(); err_handler_example(); trace_example(); // Flush all *registered* loggers using a worker thread every 3 seconds. // note: registered loggers *must* be thread safe for this to work correctly! spdlog::flush_every(std::chrono::seconds(3)); // Apply some function on all registered loggers spdlog::apply_all([&](std::shared_ptr l) { l->info(\"End of example.\"); }); // Release all spdlog resources, and drop all loggers in the registry. // This is optional (only mandatory if using windows + async log). //spdlog::shutdown(); } // Exceptions will only be thrown upon failed logger or sink construction (not during logging). catch (const spdlog::spdlog_ex &ex) { std::printf(\"Log initialization failed: %s\\n\", ex.what()); return; } // added to this example file allow multiple runs of function spdlog::drop(\"console\"); spdlog::drop(\"file_logger\"); spdlog::drop(\"some_logger_name\"); spdlog::drop(\"daily_logger\"); spdlog::drop(\"async_file_logger\"); } #include \"spdlog/sinks/stdout_color_sinks.h\" // or #include \"spdlog/sinks/stdout_sinks.h\" if no colors needed. void stdout_logger_example() { // Create color multi threaded logger. auto console = spdlog::stdout_color_mt(\"console\"); // or for stderr: // auto console = spdlog::stderr_color_mt(\"error-logger\"); } #include \"spdlog/sinks/basic_file_sink.h\" void basic_example() { // Create basic file logger (not rotated). auto my_logger = spdlog::basic_logger_mt(\"file_logger\", \"logs/basic-log.txt\"); } #include \"spdlog/sinks/rotating_file_sink.h\" void rotating_example() { // Create a file rotating logger with 5mb size max and 3 rotated files. auto rotating_logger = spdlog::rotating_logger_mt(\"some_logger_name\", \"logs/rotating.txt\", 1048576 * 5, 3); } #include \"spdlog/sinks/daily_file_sink.h\" void daily_example() { // Create a daily logger - a new file is created every day on 2:30am. auto daily_logger = spdlog::daily_logger_mt(\"daily_logger\", \"logs/daily.txt\", 2, 30); } // Clone a logger and give it new name. // Useful for creating component/subsystem loggers from some \"root\" logger. void clone_example() { auto network_logger = spdlog::default_logger()->clone(\"network\"); network_logger->info(\"Logging network stuff..\"); } #include \"spdlog/async.h\" void async_example() { // Default thread pool settings can be modified *before* creating the async logger: // spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread. auto async_file = spdlog::basic_logger_mt(\"async_file_logger\", \"logs/async_log.txt\"); // alternatively: // auto async_file = // spdlog::create_async(\"async_file_logger\", // \"logs/async_log.txt\"); for (int i = 1; i < 101; ++i) { async_file->info(\"Async message #{}\", i); } } // Log binary data as hex. // Many types of std::container types can be used. // Iterator ranges are supported too. // Format flags: // {:X} - print in uppercase. // {:s} - don't separate each byte with space. // {:p} - don't print the position on each line start. // {:n} - don't split the output to lines. #include \"spdlog/fmt/bin_to_hex.h\" void binary_example() { std::vector buf; for (int i = 0; i < 80; i++) { buf.push_back(static_cast(i & 0xff)); } spdlog::info(\"Binary example: {}\", spdlog::to_hex(buf)); spdlog::info(\"Another binary example:{:n}\", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10)); // more examples: // logger->info(\"uppercase: {:X}\", spdlog::to_hex(buf)); // logger->info(\"uppercase, no delimiters: {:Xs}\", spdlog::to_hex(buf)); // logger->info(\"uppercase, no delimiters, no position info: {:Xsp}\", spdlog::to_hex(buf)); } // Compile time log levels. // define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE) void trace_example() { // trace from default logger SPDLOG_TRACE(\"Some trace message.. {} ,{}\", 1, 3.23); // debug from default logger SPDLOG_DEBUG(\"Some debug message.. {} ,{}\", 1, 3.23); // trace from logger object auto logger = spdlog::get(\"file_logger\"); SPDLOG_LOGGER_TRACE(logger, \"another trace message\"); } // A logger with multiple sinks (stdout and file) - each with a different format and log level. void multi_sink_example() { auto console_sink = std::make_shared(); console_sink->set_level(spdlog::level::warn); console_sink->set_pattern(\"[multi_sink_example] [%^%l%$] %v\"); auto file_sink = std::make_shared(\"logs/multisink.txt\", true); file_sink->set_level(spdlog::level::trace); spdlog::logger logger(\"multi_sink\", {console_sink, file_sink}); logger.set_level(spdlog::level::debug); logger.warn(\"this should appear in both console and file\"); logger.info(\"this message should not appear in the console, only in the file\"); } // User defined types logging by implementing operator<< #include \"spdlog/fmt/ostr.h\" // must be included struct my_type { int i; template friend OStream &operator<<(OStream &os, const my_type &c) { return os << \"[my_type i=\" << c.i << \"]\"; } }; void user_defined_example() { spdlog::info(\"user defined type: {}\", my_type{14}); } // Custom error handler. Will be triggered on log failure. void err_handler_example() { // can be set globally or per logger(logger->set_error_handler(..)) spdlog::set_error_handler([](const std::string &msg) { printf(\"*** Custom log error handler: %s ***\\n\", msg.c_str()); }); } // syslog example (linux/osx/freebsd) #ifndef _WIN32 #include \"spdlog/sinks/syslog_sink.h\" void syslog_example() { std::string ident = \"spdlog-example\"; auto syslog_logger = spdlog::syslog_logger_mt(\"syslog\", ident, LOG_PID); syslog_logger->warn(\"This is warning that will end up in syslog.\"); } #endif // Android example. #if defined(__ANDROID__) #include \"spdlog/sinks/android_sink.h\" void android_example() { std::string tag = \"spdlog-android\"; auto android_logger = spdlog::android_logger_mt(\"android\", tag); android_logger->critical(\"Use \\\"adb shell logcat\\\" to view this message.\"); } #endif /*** R exampleTwo() */ We are not showing the output here; it can be compiled, linked, loaded and run just as above by simply passing the filename to Rcpp::sourceCpp() . Note that is will create a few demonstration logfiles so you may want to run the example from a temporary directory.","title":"Second example: Showcase"},{"location":"vignette/introduction/#third-example-colour","text":"The next example highlights a colour 'sink' for the logger. Again, do not use this as a starting point for your package as R CMD check will protest about use of stdout . #include \"spdlog/spdlog.h\" #include \"spdlog/sinks/stdout_color_sinks.h\" #include // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleThree() { auto console = spdlog::stdout_color_mt(\"console\"); // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%^%L%$] [thread %t] %v\"); spdlog::info(\"This an info message with custom format\"); //spdlog::set_pattern(\"%+\"); // back to default format spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); // added to this example file allow multiple runs of different package functions spdlog::drop(\"console\"); } /*** R exampleThree() */ When running this example in a terminal capable of displaying colour escape sequence, the logging levels are distinguished by colour. This ranges from green (\"info\") to yellow (\"warning\") to red (\"error\") and white-on-red (\"critical\"). Not that in this vignette color from standard output does how not show (in the keep-it-simple-mode we are using here). R> exampleThree() [14:47:52.260692] [I] [thread 2502026] This an info message with custom format [14:47:52.260715] [I] [thread 2502026] Welcome to spdlog! [14:47:52.260732] [E] [thread 2502026] Some error message with arg: 1 [14:47:52.260734] [W] [thread 2502026] Easy padding in numbers like 00000012 [14:47:52.260736] [C] [thread 2502026] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [14:47:52.260739] [I] [thread 2502026] Support for floats 1.23 [14:47:52.260741] [I] [thread 2502026] Positional args are supported too.. [14:47:52.260743] [I] [thread 2502026] left aligned R>","title":"Third example: Colour"},{"location":"vignette/introduction/#fourth-example-dedicated-r-logger","text":"The next example is suitable for use in R packages, and in fact included as an example in the package. We include the source file src/exampleRsink.cpp . // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include #include // also support stopwatch feature //' spdlog Example using a sink for R //' //' A simple example invoking a derived R/Rcpp logger. Also demonstrates the //' stopwatch feature. For more features see the 'spdlog' documnetation. //' //' Note that this no longer triggers R warnings thanks to excellent help by //' Gabi Melman. //' @return None //' @examples //' exampleRsink() // [[Rcpp::export]] void exampleRsink() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed spdlog::set_default_logger(sp); // and set as default spdlog::stopwatch sw; // instantiate a stop watch // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::info(\"Elapsed time: {}\", sw); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::info(\"Elapsed time: {}\", sw); } //' spdlog Logging Lever Setter //' //' A helper function to turn a logging level given as string //' into the current logging level //' //' @param name A string with the logging level. Value understood are, //' in decreasing verbosity \\sQuote{trace}, \\sQuote{debug}, \\sQuote{info}, //' \\sQuote{warning}, \\sQuote{error}, \\sQuote{critical}, and \\sQuote{off}. //' Unrecognised names are equivalent to \\sQuote{off}. //' @return Nothing is returned. // [[Rcpp::export]] void setLogLevel(const std::string &name) { spdlog::set_level(spdlog::level::from_str(name)); } The example file contains three key aspects to highlight: - use of the r_sink_mt() class for R-specific logger sink - use of the very convenient stopwatch object - use of logging levels We highlight these below after first showing the relevant output: R> exampleRsink() [16:52:12.076751] [fromR] [I] [thread 2453030] Welcome to spdlog! [16:52:12.076809] [fromR] [E] [thread 2453030] Some error message with arg: 1 [16:52:12.076823] [fromR] [I] [thread 2453030] Elapsed time: 9.6104e-05 [16:52:12.076833] [fromR] [W] [thread 2453030] Easy padding in numbers like 00000012 [16:52:12.076844] [fromR] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [16:52:12.076853] [fromR] [I] [thread 2453030] Support for floats 1.23 [16:52:12.076871] [fromR] [I] [thread 2453030] Positional args are supported too.. [16:52:12.076879] [fromR] [I] [thread 2453030] left aligned [16:52:12.076892] [fromR] [I] [thread 2453030] Elapsed time: 0.000167057 R>","title":"Fourth Example: Dedicated R Logger"},{"location":"vignette/introduction/#r-specific-sink","text":"spdlog has the ability to derive and sub-class sinks for logger. The RcppSpdlog package uses this feature to implement a sink using the Rcpp conduit Rcpp::Rcout instead of std::cout as it conveniently redirects to the R output stream. This class should be the default one for any R packages wanting to use spdlog while also passing R CMD check . A second important aspect of the initial code in function exampleRsink() is how a named logging instance is requested. If none is found, a new one is instantiated. Next, this logger is made the default logger permitting convenient programmatic access via spdlog:: .","title":"R-specific sink"},{"location":"vignette/introduction/#stopwatch","text":"A powerful (recent) feature of the include fmt library is the automatic formatting of timestamps and interval. As the code example shows, simply instantianting an object, here called sw , and referring to it later is all that takes.","title":"Stopwatch"},{"location":"vignette/introduction/#log-level","text":"A second utility function setLogLevel() is also provided. Usage is simple: after calling it with a given level, only message equal to it or higher are shown as the next example shows. R> setLogLevel(\"error\") R> exampleRsink() [16:54:12.666261] [fromR] [E] [thread 2453030] Some error message with arg: 1 [16:54:12.666286] [fromR] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 R> By requestion level 'error', message of level 'info', 'warning' or 'debug' are suppressed but messages levels 'error' or 'critical' as shown as desired.","title":"Log-Level"},{"location":"vignette/introduction/#fifth-example-initialization","text":"Package desiring to use RcppSpdlog can initialize its facilities during startup. For that we first define a setup function // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include //' Set a new default logger for R //' // [[Rcpp::export]] void setDefault() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed sp->set_pattern(\"[%H:%M:%S.%f] [%^%L%$] %v\"); spdlog::set_default_logger(sp); } We can then call this function during startup: .onLoad <- function(libname, pkgname) { setDefault(); }","title":"Fifth Example: Initialization"},{"location":"vignette/introduction/#sixth-example-compile-time-selection","text":"Of course, spdlog also supports a common usage paradigm with loggers in which the decision of whether to log or not is compile-time rather than run time. As this is typically implemented via macros, usage is via upper-case macros as well. The following example shows a function with three different logging-level statements as well as a #define set such one and only one is shown. Similarly, code can contain debug or trace or info or ... statements which would not appear in the actually loaded \"production code\" (or CRAN version) if the compile-time logging level define is set high enough. // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include // A define such as this could also be set in src/Makevars via a -D flag #define SPDLOG_LOG_LEVEL SPDLOG_LEVEL_CRITICAL // [[Rcpp::export]] void demoInvisible() { Rcpp::Rcout << \"Hello from demoInvisible, just to show we're being called...\\n\"; // trace message via default logger SPDLOG_TRACE(\"Some trace message.. {} ,{}\", 1, 3.23); // debug message via default logger SPDLOG_DEBUG(\"Some debug message.. {} ,{}\", 1, 3.23); // debug message via default logger SPDLOG_CRITICAL(\"Some critical message.. {} ,{}\", 1, 3.23); } When a piece of code with such compile-time defines is used, we see the expected outcome. The following example uses default logger, and as the preceding section showed this can be set up to be the custom R sink: R> Rcpp::sourceCpp(\"/tmp/rcppspdlog.cpp\") # plus a '// [[Rcpp:depends(\"RcppSpdlog\")' R> demoInvisible() Hello from demoInvisible, just to show we're being called... [08:44:48.198075] [fromR] [C] [thread 2453030] Some critical message.. 1 ,3.23 R>","title":"Sixth Example: Compile-time Selection"},{"location":"vignette/introduction/#seventh-example-access-from-r","text":"As of package 0.0.9, RcppSpdlog supports two new modes. The first is direct logging support from R and described in this section; the second is access from another R package and described thereafter. A number of basic functions are exported using Rcpp. These include log_setup(name, level) to instantiate a named logger at a given level (instead of an unnamed default at level 'warn'), log_filesetup(filename, name, level) (same using the named file as logging destination), a helper log_drop(name) to drop a named logger, two setters log_set_pattern() and log_set_level() to set, respectively, the displayed log pattern and the level. This is complemented by the actual loggers ranging from log_trace() and log_debug() to log_info() , log_warn() , log_error() and finally log_critical() . The following example (also the example in the manual page) illustrates. > library(RcppSpdlog) > log_setup(\"demo\") # default level 'warn' is used > log_info(\"this message is NOT seen\") > log_set_level(\"debug\") > log_set_pattern(\"%^[%H:%M:%S.%e] [%n] [%l] %v%$\") # set a pattern w/o process id > log_info(\"this message is seen\") [15:55:34.150] [demo] [info] this message is seen > log_warn(\"as is this message\") [ 15:55:37.513] [demo] [warning] as is this message > The interface expects a character value so use from either sprintf() or a string-interpolating helper such as glue::glue can be used: > log_info(sprintf(\"We can %s a %s with values %d\", \"build\", \"text\", 42L)) [16:03:37.728] [demo] [info] We can build a text with values 42 > log_info(glue::glue(\"We can {a} a {b} with values {v}\", a=\"build\", b=\"text\", v=42L)) [16:03:46.395] [demo] [info] We can build a text with values 42 >","title":"Seventh Example: Access From R"},{"location":"vignette/introduction/#eight-example-access-from-another-r-package","text":"As of package 0.0.9, another package can use the C++ level functions (either with or without the R functions) by importing the RcppSpdlog while ensuring at least one function from the package is imported (so that the C-level interface functions are instantiated by R). This is time-honoured mechanism long-used by lme4 to access (compiled) functions from Matrix as well as by xts to access code from zoo , and others. To properly import the package, add just one import, for example importFrom((RcppSpdlog, log_setup) to the NAMESPACE file of your package, along with the required Imports: RcppSpdlog in the DESCRIPTION file. The available functions are the same as the ones described in the previous section, but now available at the C++ level in the RcppSpdlog namespace. So for example #include RcppSpdlog::log_setup(\"demoLogger\", \"info\"); // create logger at info level RcppSpdlog::log_info(\"logger created\"); will work.","title":"Eight Example: Access From Another R Package"},{"location":"vignette/introduction/#nineth-example-more-compact-c-access","text":"As the (auto-generated, thanks to Rcpp ) interface described in the previous section is a little \"wordy\", we added a simple aliasing wrapping in a new namespace spdl and, given the protection from naming collisions offered by the namespace, shortened the accessor function names. So the previous example can also be used via #include spdl::setup(\"demoLogger\", \"info\"); // create logger at info level spdl::info(\"logger created\"); The logger interface takes a simple string. Two easy options exist for formatting such as string. First, one can rely on the tinyformat version included with Rcpp and use tfm::format() which works with standard printf() operators. Second, one can use the fmt library included with spdlog via an explicit call. # using tfm::format spdl::info(tfm::format(\"We %s values %d and %f\", \"log\", 42, 1.23)); # using fmt::format spdl::info(fmt::format(\"We {} values {} and {}\", \"log\", 42, 1.23)); Here both formatters have to be called explicitly as we use a simple one-function signature (per logging function) to the underlying C language implementation without the fuller flexibility of variadic arguments. As C++11 can be assumed, we can also offers a variadic template expansion for fmt::format() and the second example simply becomes spdl::info(\"We {} values {} and {}\", \"log\", 42, 1.23);","title":"Nineth Example: More compact C++ Access"},{"location":"vignette/introduction/#tenth-example-more-compact-r-access","text":"As the more compact access in the previous section is quite compelling we also created a sibbling R package spd providing a spdl namespace in R allowing _the exact same format strings too`. So spdl::info(\"We {} values {} and {}\", \"log\", 42L, 1.23); now also works from R using the same formatting string. We inted to upload spdl to CRAN too. Note that other all other formatting options are supported from R: the first argument is a character variable which can be constructed using paste , sprintf , or any of the string-interpolating packages. But as none of those methods works like fmt (which we have come to like a lot) we added support for it too.","title":"Tenth Example: More compact R Access"},{"location":"vignette/introduction/#conclusion","text":"spdlog and the included fmt are two very powerful and widely used C++ libraries. The RcppSpdlog package adds to them to the set of packages R users can deploy. The spd package makes access even easier and more consistent. It is our hope that the examples shown here are of interest to R users who are looking for effortless, performant and flexible logging solutions for their R packages.","title":"Conclusion"}]} \ No newline at end of file +{"config":{"indexing":"full","lang":["en"],"min_search_length":3,"prebuild_index":false,"separator":"[\\s\\-]+"},"docs":[{"location":"","text":"Bundling of spdlog for use from R and Rcpp About The spdlog library is a widely-used and very capable header-only C++ library for logging. This package includes its headers as an R package to permit other R packages to deploy it via a simple LinkingTo: RcppSpdlog as described in Section 1.1.3 of WRE . As of version 0.0.9, it also provides both simple R logging functions and compiled functions callable by other packages as described in Section 5.4.3 of WRE . Example 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 a one-char code for info, error, warning or critical followed by the thread id and the actual loggable message. The code, apart from the included headers and more, is simply // [[Rcpp::export]] void exampleOne() { // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%L] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug(\"This message should be displayed..\"); // Compile time log levels // define SPDLOG_ACTIVE_LEVEL to desired level SPDLOG_TRACE(\"Some trace message with param {}\", {}); SPDLOG_DEBUG(\"Some debug message\"); } Many other customizations are possible, see the spdlog wiki . Note that using spdlog examples directly may well trigger warning from R during package checking as stdout and/or stderr may be used. See the included example function described in the next section which uses a derived class to pass logging output explicitly to the R input/output stream as per the R coding requirements, see Section 1.3.1 (and others) of WRE . Use in R Packages and Warnings As shipped, both spdlog and the embedded fmt use stdout and stderr in ways that may make it non-trivial to fully replace them with R input/output as required by Section 1.3.1 (and others) of WRE . However, based on some initial trials and some excellent help from upstream we have defined a specific sink for R in the header rcpp_sink.h , corrected one stderr use and added one #define . That combination now passes as can be seen in checks of the package RcppSpdlog and the included function exampleRsink() whose complete source code is included here: // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include //' spdlog Example using a sink for R //' //' A simple example invoking a derived R/Rcpp logger. Also demonstrates the //' stopwatch feature. For more features see the 'spdlog' documnetation. //' //' Note that this no longer triggers R warnings thanks to excellent help by //' Gabi Melman. //' @return None //' @examples //' exampleRsink() // [[Rcpp::export]] void exampleRsink() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed spdlog::stopwatch sw; // instantiate a stop watch // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::info(\"Elapsed time: {}\", sw); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::info(\"Elapsed time: {}\", sw); } Note that it is deliberately similar in use to the example above. A new instance of the logger is instantiated as a shared pointer sp to a spdlog object. Similarly, a stopwatch is instantiated used simply by referring to it. We may make additional package features available in the future. See Also The spdl package, now also on CRAN, wraps around this package to provide a uniform and consistent logging interface from both R and C++. It defines a new C++ namespace spdl along with matching R functions. Author Gabi Melman is the main author of spdlog . Victor Zverovich is the main author of the embedded fmt library. Dirk Eddelbuettel is author of this package and the R integration. License spdlog and fmt are under the MIT license. RcppSpdlog is released under the GNU GPL, version 2 or later, just like R and Rcpp.","title":"RcppSpdlog"},{"location":"#bundling-of-spdlog-for-use-from-r-and-rcpp","text":"","title":"Bundling of spdlog for use from R and Rcpp"},{"location":"#about","text":"The spdlog library is a widely-used and very capable header-only C++ library for logging. This package includes its headers as an R package to permit other R packages to deploy it via a simple LinkingTo: RcppSpdlog as described in Section 1.1.3 of WRE . As of version 0.0.9, it also provides both simple R logging functions and compiled functions callable by other packages as described in Section 5.4.3 of WRE .","title":"About"},{"location":"#example","text":"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 a one-char code for info, error, warning or critical followed by the thread id and the actual loggable message. The code, apart from the included headers and more, is simply // [[Rcpp::export]] void exampleOne() { // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%L] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug(\"This message should be displayed..\"); // Compile time log levels // define SPDLOG_ACTIVE_LEVEL to desired level SPDLOG_TRACE(\"Some trace message with param {}\", {}); SPDLOG_DEBUG(\"Some debug message\"); } Many other customizations are possible, see the spdlog wiki . Note that using spdlog examples directly may well trigger warning from R during package checking as stdout and/or stderr may be used. See the included example function described in the next section which uses a derived class to pass logging output explicitly to the R input/output stream as per the R coding requirements, see Section 1.3.1 (and others) of WRE .","title":"Example"},{"location":"#use-in-r-packages-and-warnings","text":"As shipped, both spdlog and the embedded fmt use stdout and stderr in ways that may make it non-trivial to fully replace them with R input/output as required by Section 1.3.1 (and others) of WRE . However, based on some initial trials and some excellent help from upstream we have defined a specific sink for R in the header rcpp_sink.h , corrected one stderr use and added one #define . That combination now passes as can be seen in checks of the package RcppSpdlog and the included function exampleRsink() whose complete source code is included here: // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include //' spdlog Example using a sink for R //' //' A simple example invoking a derived R/Rcpp logger. Also demonstrates the //' stopwatch feature. For more features see the 'spdlog' documnetation. //' //' Note that this no longer triggers R warnings thanks to excellent help by //' Gabi Melman. //' @return None //' @examples //' exampleRsink() // [[Rcpp::export]] void exampleRsink() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed spdlog::stopwatch sw; // instantiate a stop watch // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::info(\"Elapsed time: {}\", sw); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::info(\"Elapsed time: {}\", sw); } Note that it is deliberately similar in use to the example above. A new instance of the logger is instantiated as a shared pointer sp to a spdlog object. Similarly, a stopwatch is instantiated used simply by referring to it. We may make additional package features available in the future.","title":"Use in R Packages and Warnings"},{"location":"#see-also","text":"The spdl package, now also on CRAN, wraps around this package to provide a uniform and consistent logging interface from both R and C++. It defines a new C++ namespace spdl along with matching R functions.","title":"See Also"},{"location":"#author","text":"Gabi Melman is the main author of spdlog . Victor Zverovich is the main author of the embedded fmt library. Dirk Eddelbuettel is author of this package and the R integration.","title":"Author"},{"location":"#license","text":"spdlog and fmt are under the MIT license. RcppSpdlog is released under the GNU GPL, version 2 or later, just like R and Rcpp.","title":"License"},{"location":"changelog/","text":"2024 2024-04-25 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.17 * inst/include/spdlog/*: New upstream release spdlog 1.14.0 2024-04-02 Dirk Eddelbuettel edd@debian.org * .github/workflows/ci.yaml (jobs): Update to actions/checkout@v4, add r-ci-setup actions 2024-01-12 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.16 * inst/include/spdlog/*: New upstream release spdlog 1.13.0 2023 2023-11-29 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.15 * src/RcppExports.cpp: Regenerated under updated Rcpp to address format string issue reported by R-devel * man/RcppSpdlog-package.Rd: Remove some empty default entries 2023-07-09 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.14 2023-07-08 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdlog/*: New upstream release spdlog 1.12.0 2023-06-28 Dirk Eddelbuettel edd@debian.org * README.md: Add r-universe badge 2023-06-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.13 2023-06-13 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp (log_init): Add a simple convenience wrapper to log_setup() which omits the first 'logger name' argument * inst/include/spdl.h: Define convenience wrappers init() and log() 2023-03-19 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/Makevars: No longer set a C++ standard * R/RcppExports.R (setLoadAction): Updated .Call using backticks 2023-01-17 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog_stopwatch.h: Define stopwatch without fmt.h header * inst/include/RcppSpdlog_types.h: Use spdlog_stopwatch if #define set 2023-01-07 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.12 2022 2022-12-27 Dirk Eddelbuettel edd@debian.org * src/interface.cpp: Add documentation reference for format pattern * man/log_setup.Rd: Idem * R/RcppExports.R: Idem 2022-12-25 Dirk Eddelbuettel edd@debian.org * inst/include/spdl.h: Wrap three RcppSpdlog::*_stopwatch() functions 2022-12-23 Dirk Eddelbuettel edd@debian.org * src/interface.cpp: Split stopwatch documentation off * man/get_stopwatch.Rd: Idem * man/log_setup.Rd: Idem * src/RcppExports.cpp: Idem * R/RcppExports.R: Idem 2022-12-22 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp: Define and document three new functions for stopwatch * R/RcppExports.R: Export new functions * src/RcppExports.cpp: Idem * inst/include/RcppSpdlog_RcppExports.h: Idem * inst/include/RcppSpdlog_types.h: Include stopwatch, add XPtr template * inst/include/RcppSpdlog: Use new header * man/log_setup.Rd: Add documentation * R/stopwatch.R: Add two S3 methods for stopwatch objects * NAMESPACE: Export methods * inst/include/rcpp_sink.h: Use lighter Rcpp interface 2022-12-13 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.11 * vignettes/introduction.md: Microedit 2022-12-12 Dirk Eddelbuettel edd@debian.org * src/interface.cpp (log_filesetup): Setup (simple) file-based logger * R/RcppExports.R: R accessor * src/RcppExports.cpp: Autogenerated export for C level access * inst/include/RcppSpdlog_RcppExports.h: Idem * inst/include/rcpp_sink.h: Added #include * man/log_setup.Rd: Added documentation * inst/include/spdl.h: Added in spdl namespace 2022-12-02 Dirk Eddelbuettel edd@debian.org * README.md: Mention the new spdl package 2022-11-18 Dirk Eddelbuettel edd@debian.org * src/formatter.cpp: Export to C++ to make formatter() callable * src/RcppExports.cpp: Autogenerated export for C level access * inst/include/RcppSpdlog_RcppExports.h: Idem 2022-11-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.10 * vignettes/introduction.md: More edits 2022-11-15 Dirk Eddelbuettel edd@debian.org * src/formatter.cpp (formatter): Add formatting helper which passes logging string to fmt::format() enable fmt's \"format\" from R * src/RcppExports.cpp: Ditto * R/RcppExports.R (formatter): Ditto * man/formatter.Rd: Docs * inst/include/spdl.h: Include fmtlib::fmt via spdlog 2022-11-14 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdl.h: Use variadic templates to fmt::format 2022-11-04 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.9 2022-11-03 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdlog/*: New upstream release spdlog 1.11.0 * vignettes/introduction.md: Small edits 2022-11-02 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.md: New sections for access from R and C++ 2022-11-01 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/RcppSpdlog: Ad second shorter namespace 'spdl' with shorter (inlined) function names as simpler accessors * vignettes/introduction.md: Two new sections on access from R and C++, respectively 2022-10-31 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version 2022-10-30 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp: Add R interface to spdlog * man/log_setup.Rd: Documentation * .github/workflows/ci.yaml (jobs): Update to actions/checkout@v3 * src/interface.cpp: Activate R and C++ interface generation * R/RcppExports.R: Updated accordingly * src/RcppExports.cpp: Idem * inst/include/RcppSpdlog.h: Generated * inst/include/RcppSpdlog_RcppExports.h: Idem 2022-04-04 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.8 * inst/include/spdlog/*: New upstream release spdlog 1.10.0 2021 2021-12-05 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.7 2021-11-20 Dirk Eddelbuettel edd@debian.org * vignettes/water.css: Added css file 2021-11-19 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * vignettes/introduction.md: Converted from Rmd to simplermarkdown * DESCRIPTION: Switched VignetteBuilder: to simplermarkdown 2021-08-12 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * inst/include/spdlog/*: New upstream release spdlog 1.9.2 2021-07-27 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * inst/include/spdlog/*: New upstream release spdlog 1.9.1 2021-07-21 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.6 * inst/include/spdlog/*: New upstream spdlog 1.9.0 (with fmt 8.x) 2021-03-28 Dirk Eddelbuettel edd@debian.org * docs/mkdmt-src/: Moved mkdocs-material input 2021-03-27 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.5 2021-03-25 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: New upstream release spdlog 1.8.4 + 1.8.5 2021-03-24 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Description): Mention Gabi explicitly (URL): List GitHub repo and package pages (BugReports): List GitHub issues pages * inst/include/spdlog/*: New upstream release spdlog 1.8.3 2020 2020-12-25 Dirk Eddelbuettel edd@debian.org * .github/workflows/ci.yaml: Small tweaks to CI YAML file 2020-12-11 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.4 * inst/include/spdlog/*: New upstream release spdlog 1.8.2 * .github/workflows/ci.yaml: Add CI runner using r-ci 2020-10-23 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.3 * docs/: Added package website * docs-src/: Added package website inputs 2020-10-19 Dirk Eddelbuettel edd@debian.org * README.md: Updated example 2020-10-08 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.Rmd (vignette): Compile-time example added 2020-10-04 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.Rmd (vignette): New (draft) vignette * DESCRIPTION (VignetteBuilder): Add knitr (Suggests): Add knitr, rmarkdown, minidown * inst/examples/exampleTwo.cpp (exampleTwo): Added cleanup at end with logger removal to permit multiple calls to example function * inst/examples/exampleThree.cpp (exampleThree): Idem 2020-10-01 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: Upgraded to upstream release 1.8.1 2020-09-30 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp (exampleRsink): Use default logger instance 2020-09-29 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp (setLogLevel): New function * R/RcppExports.R (exampleRsink): R accessor * man/setLogLevel.Rd: Documentation 2020-09-28 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/logger-inl.h: Synchronised with our PR #1685 switching to REprintf() if R_R_H and USING_R defined * inst/include/RcppSpdlog: Include R.h so that R_R_H and USING_R defined, define SPDLOG_DISABLE_DEFAULT_LOGGER here * src/exampleRsink.cpp: Removed SPDLOG_DISABLE_DEFAULT_LOGGER def. 2020-09-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.2 * inst/include/spdlog/*: Upgraded to upstream release 1.8.0 * inst/include/spdlog/logger-inl.h: Switch to REprintf as before * .travis.yml: Use BSPM, turn os macOS * src/exampleRsink.cpp (exampleRsink): Add 'stopwatch' demo 2020-09-08 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.1 2020-08-21 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp: Renamed from exampleFour() * man/exampleRsink.Rd: Idem * src/RcppExports.cpp: Updated * R/RcppExports.R: Idem * README.md: Some more edits 2020-08-20 Dirk Eddelbuettel edd@debian.org * inst/include/RcppSpdlog: Easy wrapper for spdlog and R sink * inst/include/rcpp_sink.h: A sink for R using Rcpp::Rcout * src/exampleFour.cpp: Rewritten and now R CMD check clean * inst/examples/examplesFour.cpp: Now in src/, R sink in its header * README.md: Edited, added two badges * cleanup: Added * .editorconfig: Idem 2020-08-19 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: Using spdlog version 1.7 * inst/examples/*: Four simple usage examples * .travis.yml: Added though no real tests present * src/exampleFour.cpp (exampleFour): Simple wrapper around simple Rcpp logger class which still triggers R warnings * man/exampleFour.Rd: Basic help page * src/RcppExports.cpp: Generated * src/Makevars: Added * R/RcppExports.R: Idem * NAMESPACE: Added * DESCRIPTION: Added Imports: and LinkingTo: for Rcpp","title":"Changelog"},{"location":"changelog/#2024","text":"2024-04-25 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.17 * inst/include/spdlog/*: New upstream release spdlog 1.14.0 2024-04-02 Dirk Eddelbuettel edd@debian.org * .github/workflows/ci.yaml (jobs): Update to actions/checkout@v4, add r-ci-setup actions 2024-01-12 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.16 * inst/include/spdlog/*: New upstream release spdlog 1.13.0","title":"2024"},{"location":"changelog/#2023","text":"2023-11-29 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.15 * src/RcppExports.cpp: Regenerated under updated Rcpp to address format string issue reported by R-devel * man/RcppSpdlog-package.Rd: Remove some empty default entries 2023-07-09 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.14 2023-07-08 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdlog/*: New upstream release spdlog 1.12.0 2023-06-28 Dirk Eddelbuettel edd@debian.org * README.md: Add r-universe badge 2023-06-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.13 2023-06-13 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp (log_init): Add a simple convenience wrapper to log_setup() which omits the first 'logger name' argument * inst/include/spdl.h: Define convenience wrappers init() and log() 2023-03-19 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/Makevars: No longer set a C++ standard * R/RcppExports.R (setLoadAction): Updated .Call using backticks 2023-01-17 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog_stopwatch.h: Define stopwatch without fmt.h header * inst/include/RcppSpdlog_types.h: Use spdlog_stopwatch if #define set 2023-01-07 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.12","title":"2023"},{"location":"changelog/#2022","text":"2022-12-27 Dirk Eddelbuettel edd@debian.org * src/interface.cpp: Add documentation reference for format pattern * man/log_setup.Rd: Idem * R/RcppExports.R: Idem 2022-12-25 Dirk Eddelbuettel edd@debian.org * inst/include/spdl.h: Wrap three RcppSpdlog::*_stopwatch() functions 2022-12-23 Dirk Eddelbuettel edd@debian.org * src/interface.cpp: Split stopwatch documentation off * man/get_stopwatch.Rd: Idem * man/log_setup.Rd: Idem * src/RcppExports.cpp: Idem * R/RcppExports.R: Idem 2022-12-22 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp: Define and document three new functions for stopwatch * R/RcppExports.R: Export new functions * src/RcppExports.cpp: Idem * inst/include/RcppSpdlog_RcppExports.h: Idem * inst/include/RcppSpdlog_types.h: Include stopwatch, add XPtr template * inst/include/RcppSpdlog: Use new header * man/log_setup.Rd: Add documentation * R/stopwatch.R: Add two S3 methods for stopwatch objects * NAMESPACE: Export methods * inst/include/rcpp_sink.h: Use lighter Rcpp interface 2022-12-13 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.11 * vignettes/introduction.md: Microedit 2022-12-12 Dirk Eddelbuettel edd@debian.org * src/interface.cpp (log_filesetup): Setup (simple) file-based logger * R/RcppExports.R: R accessor * src/RcppExports.cpp: Autogenerated export for C level access * inst/include/RcppSpdlog_RcppExports.h: Idem * inst/include/rcpp_sink.h: Added #include * man/log_setup.Rd: Added documentation * inst/include/spdl.h: Added in spdl namespace 2022-12-02 Dirk Eddelbuettel edd@debian.org * README.md: Mention the new spdl package 2022-11-18 Dirk Eddelbuettel edd@debian.org * src/formatter.cpp: Export to C++ to make formatter() callable * src/RcppExports.cpp: Autogenerated export for C level access * inst/include/RcppSpdlog_RcppExports.h: Idem 2022-11-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.10 * vignettes/introduction.md: More edits 2022-11-15 Dirk Eddelbuettel edd@debian.org * src/formatter.cpp (formatter): Add formatting helper which passes logging string to fmt::format() enable fmt's \"format\" from R * src/RcppExports.cpp: Ditto * R/RcppExports.R (formatter): Ditto * man/formatter.Rd: Docs * inst/include/spdl.h: Include fmtlib::fmt via spdlog 2022-11-14 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdl.h: Use variadic templates to fmt::format 2022-11-04 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.9 2022-11-03 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/spdlog/*: New upstream release spdlog 1.11.0 * vignettes/introduction.md: Small edits 2022-11-02 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.md: New sections for access from R and C++ 2022-11-01 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * inst/include/RcppSpdlog: Ad second shorter namespace 'spdl' with shorter (inlined) function names as simpler accessors * vignettes/introduction.md: Two new sections on access from R and C++, respectively 2022-10-31 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version 2022-10-30 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll micro release version * src/interface.cpp: Add R interface to spdlog * man/log_setup.Rd: Documentation * .github/workflows/ci.yaml (jobs): Update to actions/checkout@v3 * src/interface.cpp: Activate R and C++ interface generation * R/RcppExports.R: Updated accordingly * src/RcppExports.cpp: Idem * inst/include/RcppSpdlog.h: Generated * inst/include/RcppSpdlog_RcppExports.h: Idem 2022-04-04 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.8 * inst/include/spdlog/*: New upstream release spdlog 1.10.0","title":"2022"},{"location":"changelog/#2021","text":"2021-12-05 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.7 2021-11-20 Dirk Eddelbuettel edd@debian.org * vignettes/water.css: Added css file 2021-11-19 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * vignettes/introduction.md: Converted from Rmd to simplermarkdown * DESCRIPTION: Switched VignetteBuilder: to simplermarkdown 2021-08-12 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * inst/include/spdlog/*: New upstream release spdlog 1.9.2 2021-07-27 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Roll minor version * inst/include/spdlog/*: New upstream release spdlog 1.9.1 2021-07-21 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.6 * inst/include/spdlog/*: New upstream spdlog 1.9.0 (with fmt 8.x) 2021-03-28 Dirk Eddelbuettel edd@debian.org * docs/mkdmt-src/: Moved mkdocs-material input 2021-03-27 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.5 2021-03-25 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: New upstream release spdlog 1.8.4 + 1.8.5 2021-03-24 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Description): Mention Gabi explicitly (URL): List GitHub repo and package pages (BugReports): List GitHub issues pages * inst/include/spdlog/*: New upstream release spdlog 1.8.3","title":"2021"},{"location":"changelog/#2020","text":"2020-12-25 Dirk Eddelbuettel edd@debian.org * .github/workflows/ci.yaml: Small tweaks to CI YAML file 2020-12-11 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.4 * inst/include/spdlog/*: New upstream release spdlog 1.8.2 * .github/workflows/ci.yaml: Add CI runner using r-ci 2020-10-23 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.3 * docs/: Added package website * docs-src/: Added package website inputs 2020-10-19 Dirk Eddelbuettel edd@debian.org * README.md: Updated example 2020-10-08 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.Rmd (vignette): Compile-time example added 2020-10-04 Dirk Eddelbuettel edd@debian.org * vignettes/introduction.Rmd (vignette): New (draft) vignette * DESCRIPTION (VignetteBuilder): Add knitr (Suggests): Add knitr, rmarkdown, minidown * inst/examples/exampleTwo.cpp (exampleTwo): Added cleanup at end with logger removal to permit multiple calls to example function * inst/examples/exampleThree.cpp (exampleThree): Idem 2020-10-01 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: Upgraded to upstream release 1.8.1 2020-09-30 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp (exampleRsink): Use default logger instance 2020-09-29 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp (setLogLevel): New function * R/RcppExports.R (exampleRsink): R accessor * man/setLogLevel.Rd: Documentation 2020-09-28 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/logger-inl.h: Synchronised with our PR #1685 switching to REprintf() if R_R_H and USING_R defined * inst/include/RcppSpdlog: Include R.h so that R_R_H and USING_R defined, define SPDLOG_DISABLE_DEFAULT_LOGGER here * src/exampleRsink.cpp: Removed SPDLOG_DISABLE_DEFAULT_LOGGER def. 2020-09-17 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.2 * inst/include/spdlog/*: Upgraded to upstream release 1.8.0 * inst/include/spdlog/logger-inl.h: Switch to REprintf as before * .travis.yml: Use BSPM, turn os macOS * src/exampleRsink.cpp (exampleRsink): Add 'stopwatch' demo 2020-09-08 Dirk Eddelbuettel edd@debian.org * DESCRIPTION (Version, Date): Version 0.0.1 2020-08-21 Dirk Eddelbuettel edd@debian.org * src/exampleRsink.cpp: Renamed from exampleFour() * man/exampleRsink.Rd: Idem * src/RcppExports.cpp: Updated * R/RcppExports.R: Idem * README.md: Some more edits 2020-08-20 Dirk Eddelbuettel edd@debian.org * inst/include/RcppSpdlog: Easy wrapper for spdlog and R sink * inst/include/rcpp_sink.h: A sink for R using Rcpp::Rcout * src/exampleFour.cpp: Rewritten and now R CMD check clean * inst/examples/examplesFour.cpp: Now in src/, R sink in its header * README.md: Edited, added two badges * cleanup: Added * .editorconfig: Idem 2020-08-19 Dirk Eddelbuettel edd@debian.org * inst/include/spdlog/*: Using spdlog version 1.7 * inst/examples/*: Four simple usage examples * .travis.yml: Added though no real tests present * src/exampleFour.cpp (exampleFour): Simple wrapper around simple Rcpp logger class which still triggers R warnings * man/exampleFour.Rd: Basic help page * src/RcppExports.cpp: Generated * src/Makevars: Added * R/RcppExports.R: Idem * NAMESPACE: Added * DESCRIPTION: Added Imports: and LinkingTo: for Rcpp","title":"2020"},{"location":"news/","text":"Version 0.0.17 (2024-04-25) Minor continuous integration update Upgraded to upstream release spdlog 1.14.0 Version 0.0.16 (2024-01-12) Upgraded to upstream release spdlog 1.13.0 Version 0.0.15 (2023-11-29) Correct default package help page slighly RcppExports.cpp has been regenerated under an updated Rcpp to address a format string warning under R-devel Version 0.0.14 (2023-07-09) Added new badge to README.md Upgraded to upstream release spdlog 1.12.0 Version 0.0.13 (2023-06-17) Minor tweak to stopwatch setup avoids pulling in fmt No longer set a C++ compilation standard as the default choices by R are sufficient for the package Add convenience wrapper log_init omitting first argument to log_setup while preserving the interface from the latter Add convenience setup wrappers init and log to API header file spdl.h Version 0.0.12 (2023-01-07) Addeed support for 'stopwatch' object allowing for simple timing (from both C++ and R) via the logging framework. The \u2018spdlog\u2019 logging pattern is documented via a reference. Version 0.0.11 (2022-12-13) Export the formatter at C level Mention package spdl in README.md Support simple file-based logger Version 0.0.10 (2022-11-17) Support variadic templates with fmt::format Add R formatting helper which converts arguments to character taking advantage of variadic template logger: fmt logging from R Expand vignette Version 0.0.9 (2022-11-04) Add both an R and an C++ interface to spdlog Update GitHub Actions to checkout@v3 Add a shorter aliased namespace for C++ Upgraded to upstream release spdlog 1.11.0 Version 0.0.8 (2022-04-04) Upgraded to upstream release spdlog 1.10.0 Version 0.0.7 (2021-12-05) Upgraded to upstream bug fix releases spdlog 1.9.1 and 1.9.2 Travis artifacts and badges have been pruned Vignette now uses simplermarkdown Version 0.0.6 (2021-07-21) Upgraded to upstream release spdlog 1.9.0 Version 0.0.5 (2020-12-11) Upgraded to upstream release spdlog 1.8.5 (and 1.8.4 and 1.8.3) Small enhancements to DESCRIPTION files Version 0.0.4 (2020-12-11) Upgraded to upstream release spdlog 1.8.2 Added GitHub Actions CI using run.sh from r-ci Version 0.0.3 (2020-10-23) New function setLogLevel with R accessor in exampleRsink example Updated exampleRsink to use default logger instance Upgraded to upstream release 1.8.1 which contains finalised upstream use to switch to REprintf() if R compilation detected Added new vignette with extensive usage examples, added compile-time logging switch example A package documentation website was added Version 0.0.2 (2020-09-17) Upgraded to upstream release 1.8.0 Switched Travis CI to using BSPM, also test on macOS Added 'stopwatch' use to main R sink example Version 0.0.1 (2020-09-08) Initial release with added R/Rcpp logging sink example","title":"News"},{"location":"man/RcppSpdlog-package/","text":"R and C++ Interfaces to 'spdlog' C++ Header Library for Logging Description The mature and widely-used C++ logging library 'spdlog' by Gabi Melman provides many desirable features. This package bundles these header files for easy use by R packages from both their R and C or C++ code. Explicit use via 'LinkingTo:' is also supported. Also see the 'spdl' package which enhanced this package with a consistent R and C++ interface. Details The DESCRIPTION file: This package was not yet installed at build time. Index: This package was not yet installed at build time. This section should provide a more detailed overview of how to use the package, including the most important functions. Author(s) Dirk Eddelbuettel Maintainer: Dirk Eddelbuettel \\ References This optional section can contain literature or other references for background information. See Also Optional links to other man pages Examples ## Optional simple examples of the most important functions ## Use \\dontrun{} around code to be shown but not executed","title":"RcppSpdlog package"},{"location":"man/RcppSpdlog-package/#r-and-c-interfaces-to-spdlog-c-header-library-for-logging","text":"","title":"R and C++ Interfaces to 'spdlog' C++ Header Library for Logging"},{"location":"man/RcppSpdlog-package/#description","text":"The mature and widely-used C++ logging library 'spdlog' by Gabi Melman provides many desirable features. This package bundles these header files for easy use by R packages from both their R and C or C++ code. Explicit use via 'LinkingTo:' is also supported. Also see the 'spdl' package which enhanced this package with a consistent R and C++ interface.","title":"Description"},{"location":"man/RcppSpdlog-package/#details","text":"The DESCRIPTION file: This package was not yet installed at build time. Index: This package was not yet installed at build time. This section should provide a more detailed overview of how to use the package, including the most important functions.","title":"Details"},{"location":"man/RcppSpdlog-package/#authors","text":"Dirk Eddelbuettel Maintainer: Dirk Eddelbuettel \\","title":"Author(s)"},{"location":"man/RcppSpdlog-package/#references","text":"This optional section can contain literature or other references for background information.","title":"References"},{"location":"man/RcppSpdlog-package/#see-also","text":"Optional links to other man pages","title":"See Also"},{"location":"man/RcppSpdlog-package/#examples","text":"## Optional simple examples of the most important functions ## Use \\dontrun{} around code to be shown but not executed","title":"Examples"},{"location":"man/exampleRsink/","text":"spdlog Example using a sink for R Description A simple example invoking a derived R/Rcpp logger. Also demonstrates the stopwatch feature. For more features see the 'spdlog' documnetation. Usage exampleRsink() Details Note that this no longer triggers R warnings thanks to excellent help by Gabi Melman. Value None Examples exampleRsink()","title":"exampleRsink"},{"location":"man/exampleRsink/#spdlog-example-using-a-sink-for-r","text":"","title":"spdlog Example using a sink for R"},{"location":"man/exampleRsink/#description","text":"A simple example invoking a derived R/Rcpp logger. Also demonstrates the stopwatch feature. For more features see the 'spdlog' documnetation.","title":"Description"},{"location":"man/exampleRsink/#usage","text":"exampleRsink()","title":"Usage"},{"location":"man/exampleRsink/#details","text":"Note that this no longer triggers R warnings thanks to excellent help by Gabi Melman.","title":"Details"},{"location":"man/exampleRsink/#value","text":"None","title":"Value"},{"location":"man/exampleRsink/#examples","text":"exampleRsink()","title":"Examples"},{"location":"man/formatter/","text":"Simple Pass-Through Formatter to fmt::format() Description The C-level interface of R does not make it easy to pass ... arguments. This helper function assumes it has already been called with format() on each argument (as a wrapper can do) so it just spreads out the class to fmt::format{} which, being C++, uses variadic templates to receive the arguments. The main motivation for this function to able to format string as use by the \u2018fmtlib::fmt\u2019 library included in \u2018spdlog\u2019 to write similar debug strings in both R and C++. This function permits R calls with multiple arguments of different types which (by being formatted on the R side) are handled as strings (whereas C++ logging has access to the templating logic). Usage formatter(s, v) Arguments s A character variable with a format string for \u2018fmtlib::fmt\u2019 v A character vector with the logging string arguments. Value A single (formatted) string See Also https://github.com/fmtlib/fmt","title":"Formatter"},{"location":"man/formatter/#simple-pass-through-formatter-to-fmtformat","text":"","title":"Simple Pass-Through Formatter to fmt::format()"},{"location":"man/formatter/#description","text":"The C-level interface of R does not make it easy to pass ... arguments. This helper function assumes it has already been called with format() on each argument (as a wrapper can do) so it just spreads out the class to fmt::format{} which, being C++, uses variadic templates to receive the arguments. The main motivation for this function to able to format string as use by the \u2018fmtlib::fmt\u2019 library included in \u2018spdlog\u2019 to write similar debug strings in both R and C++. This function permits R calls with multiple arguments of different types which (by being formatted on the R side) are handled as strings (whereas C++ logging has access to the templating logic).","title":"Description"},{"location":"man/formatter/#usage","text":"formatter(s, v)","title":"Usage"},{"location":"man/formatter/#arguments","text":"s A character variable with a format string for \u2018fmtlib::fmt\u2019 v A character vector with the logging string arguments.","title":"Arguments"},{"location":"man/formatter/#value","text":"A single (formatted) string","title":"Value"},{"location":"man/formatter/#see-also","text":"https://github.com/fmtlib/fmt","title":"See Also"},{"location":"man/get_stopwatch/","text":"R Accessor Functions for spdlog Stopwatch Description A set of functions provides access to the spdlog stopwatch facilty. As stopwatch object is a simple container around a C++ std::chrono object which (essentially) reports elapsed-time since creation. The object is exported to R via an external pointer permitting use from both R and C++. Usage get_stopwatch() elapsed_stopwatch(sw) format_stopwatch(sw) ## S3 method for class 'stopwatch' print(x, ...) ## S3 method for class 'stopwatch' format(x, ...) Arguments sw An S3 object of type stopwatch . x An S3 object of type stopwatch . ... Dotted argument required by generic, unused here. Details Several functions are provided: get_stopwatch Returns a stopwatch object (as an S3 object). elapsed_stopwatch Returns elapsed time for stopwatch in seconds. format_stopwatch Returns elapsed time for stopwatch as character variable. The stopwatch object has print and format methods. Value The desired object is returned: respectively, a stopwatch object as an external pointer in an S3 class, the elapsed time in seconds as a double, or formatted as a character variable. Examples w <- get_stopwatch() Sys.sleep(0.2) elapsed_stopwatch(w) format_stopwatch(w)","title":"Get stopwatch"},{"location":"man/get_stopwatch/#r-accessor-functions-for-spdlog-stopwatch","text":"","title":"R Accessor Functions for spdlog Stopwatch"},{"location":"man/get_stopwatch/#description","text":"A set of functions provides access to the spdlog stopwatch facilty. As stopwatch object is a simple container around a C++ std::chrono object which (essentially) reports elapsed-time since creation. The object is exported to R via an external pointer permitting use from both R and C++.","title":"Description"},{"location":"man/get_stopwatch/#usage","text":"get_stopwatch() elapsed_stopwatch(sw) format_stopwatch(sw) ## S3 method for class 'stopwatch' print(x, ...) ## S3 method for class 'stopwatch' format(x, ...)","title":"Usage"},{"location":"man/get_stopwatch/#arguments","text":"sw An S3 object of type stopwatch . x An S3 object of type stopwatch . ... Dotted argument required by generic, unused here.","title":"Arguments"},{"location":"man/get_stopwatch/#details","text":"Several functions are provided: get_stopwatch Returns a stopwatch object (as an S3 object). elapsed_stopwatch Returns elapsed time for stopwatch in seconds. format_stopwatch Returns elapsed time for stopwatch as character variable. The stopwatch object has print and format methods.","title":"Details"},{"location":"man/get_stopwatch/#value","text":"The desired object is returned: respectively, a stopwatch object as an external pointer in an S3 class, the elapsed time in seconds as a double, or formatted as a character variable.","title":"Value"},{"location":"man/get_stopwatch/#examples","text":"w <- get_stopwatch() Sys.sleep(0.2) elapsed_stopwatch(w) format_stopwatch(w)","title":"Examples"},{"location":"man/log_setup/","text":"R Accessor Functions for spdlog Logger Description Several R-level functions can access the spdlog logging facilties. As spdlog is a C++-level logging library, these are R function permit concurrent logging from both R and C++. Usage log_setup(name = \"default\", level = \"warn\") log_init(level = \"warn\") log_filesetup(filename, name = \"default\", level = \"warn\") log_drop(name) log_set_pattern(s) log_set_level(s) log_trace(s) log_debug(s) log_info(s) log_warn(s) log_error(s) log_critical(s) Arguments name A character variable with the logging instance name, default value is \u2018default\u2019. level A character variable with the default logging level, default value is \u2018warn\u2019. filename A character variable with the logging filename if a file-based logger is instantiated. s A character variable with the logging pattern, level or message. Details Several functions are provided: log_setup Initializes a logger (which becomes the default logger). log_filesetup Initializes a file-based logger (which becomes the default). log_drop Removes logger (which in general should not be needed). log_set_pattern Changes the default logging message pattern. log_set_level Sets the logging level threshold. log_trace Logs a trace-level message. log_debug Logs a debug-level message. log_info Logs a info-level message. log_warn Logs a warn-level message. log_error Logs a error-level message. log_critical Logs a critical-level message. Supported logging levels are, in order of increasing threshold values, \u2018trace\u2019, \u2018debug\u2019, \u2018warn\u2019, \u2018info\u2019, \u2018warn\u2019, \u2018error\u2019, and \u2018critical\u2019. A message issued below the current threshold is not displayed whereas a message at or above the current threshold is displayed. The default level is \u2018warn\u2019. Value Nothing is returned from these functions as they are invoked for their side-effects. See Also The logging pattern format is described in at the repo in the page https://github.com/gabime/spdlog/wiki/3.-Custom-formatting . Examples log_setup(\"demo\") # at default level 'warn' log_info(\"this message is NOT seen\") log_set_level(\"debug\") log_info(\"this message is seen\") log_warn(\"as is this message\")","title":"Log setup"},{"location":"man/log_setup/#r-accessor-functions-for-spdlog-logger","text":"","title":"R Accessor Functions for spdlog Logger"},{"location":"man/log_setup/#description","text":"Several R-level functions can access the spdlog logging facilties. As spdlog is a C++-level logging library, these are R function permit concurrent logging from both R and C++.","title":"Description"},{"location":"man/log_setup/#usage","text":"log_setup(name = \"default\", level = \"warn\") log_init(level = \"warn\") log_filesetup(filename, name = \"default\", level = \"warn\") log_drop(name) log_set_pattern(s) log_set_level(s) log_trace(s) log_debug(s) log_info(s) log_warn(s) log_error(s) log_critical(s)","title":"Usage"},{"location":"man/log_setup/#arguments","text":"name A character variable with the logging instance name, default value is \u2018default\u2019. level A character variable with the default logging level, default value is \u2018warn\u2019. filename A character variable with the logging filename if a file-based logger is instantiated. s A character variable with the logging pattern, level or message.","title":"Arguments"},{"location":"man/log_setup/#details","text":"Several functions are provided: log_setup Initializes a logger (which becomes the default logger). log_filesetup Initializes a file-based logger (which becomes the default). log_drop Removes logger (which in general should not be needed). log_set_pattern Changes the default logging message pattern. log_set_level Sets the logging level threshold. log_trace Logs a trace-level message. log_debug Logs a debug-level message. log_info Logs a info-level message. log_warn Logs a warn-level message. log_error Logs a error-level message. log_critical Logs a critical-level message. Supported logging levels are, in order of increasing threshold values, \u2018trace\u2019, \u2018debug\u2019, \u2018warn\u2019, \u2018info\u2019, \u2018warn\u2019, \u2018error\u2019, and \u2018critical\u2019. A message issued below the current threshold is not displayed whereas a message at or above the current threshold is displayed. The default level is \u2018warn\u2019.","title":"Details"},{"location":"man/log_setup/#value","text":"Nothing is returned from these functions as they are invoked for their side-effects.","title":"Value"},{"location":"man/log_setup/#see-also","text":"The logging pattern format is described in at the repo in the page https://github.com/gabime/spdlog/wiki/3.-Custom-formatting .","title":"See Also"},{"location":"man/log_setup/#examples","text":"log_setup(\"demo\") # at default level 'warn' log_info(\"this message is NOT seen\") log_set_level(\"debug\") log_info(\"this message is seen\") log_warn(\"as is this message\")","title":"Examples"},{"location":"man/setLogLevel/","text":"spdlog Logging Lever Setter Description A helper function to turn a logging level given as string into the current logging level Usage setLogLevel(name) Arguments name A string with the logging level. Value understood are, in decreasing verbosity \u2018trace\u2019, \u2018debug\u2019, \u2018info\u2019, \u2018warning\u2019, \u2018error\u2019, \u2018critical\u2019, and \u2018off\u2019. Unrecognised names are equivalent to \u2018off\u2019. Value Nothing is returned.","title":"setLogLevel"},{"location":"man/setLogLevel/#spdlog-logging-lever-setter","text":"","title":"spdlog Logging Lever Setter"},{"location":"man/setLogLevel/#description","text":"A helper function to turn a logging level given as string into the current logging level","title":"Description"},{"location":"man/setLogLevel/#usage","text":"setLogLevel(name)","title":"Usage"},{"location":"man/setLogLevel/#arguments","text":"name A string with the logging level. Value understood are, in decreasing verbosity \u2018trace\u2019, \u2018debug\u2019, \u2018info\u2019, \u2018warning\u2019, \u2018error\u2019, \u2018critical\u2019, and \u2018off\u2019. Unrecognised names are equivalent to \u2018off\u2019.","title":"Arguments"},{"location":"man/setLogLevel/#value","text":"Nothing is returned.","title":"Value"},{"location":"vignette/introduction/","text":"Introducing RcppSpdlog spdlog is a widely-used and very capable header-only C++ library for logging. The RcppSpdlog package provides R users with easy-to-use customized access to the spdlog logging library by including its headers in an R package which permit other R packages to deploy it via a simple LinkingTo: RcppSpdlog as described in Section 1.1.3 of WRE . spdlog is mature and widely deployed. It also has a very rich set of features described at the repository wiki . This vignette will highlight a few first use cases. Note that in order to use RcppSpdlog in an R package that might get distributed to CRAN , the code should follow the example R and C++ code in function exampleRsink() as described below. We will however start with some simpler examples. Do not copy those into your R package. The package checks used by R test for use of stdout and stderr which is why the customized setup described later is preferable. Initial example: Basics This example follows the simplest and initial example in the spdlog . It is also included in the RcppSpdlog package as examples/exampleOne.cpp . As discussed above, do not use this example as a starting point in an R package. // based on the 'basic usage' example in the README.md at https://github.com/gabime/spdlog #include \"spdlog/spdlog.h\" #include // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleOne() { // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%L] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug(\"This message should be displayed..\"); // Compile time log levels // define SPDLOG_ACTIVE_LEVEL to desired level SPDLOG_TRACE(\"Some trace message with param {}\", {}); SPDLOG_DEBUG(\"Some debug message\"); } /*** R exampleOne() */ When built, which is easiest via Rcpp::sourceCpp() , the final block ensures that the created function exampleOne() is executed. In one previous run, the following output was produded: R> exampleOne() [14:25:03.362024] [I] [thread 2453030] Welcome to spdlog! [14:25:03.362047] [E] [thread 2453030] Some error message with arg: 1 [14:25:03.362051] [W] [thread 2453030] Easy padding in numbers like 00000012 [14:25:03.362053] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [14:25:03.362056] [I] [thread 2453030] Support for floats 1.23 [14:25:03.362058] [I] [thread 2453030] Positional args are supported too.. [14:25:03.362060] [I] [thread 2453030] left aligned [14:25:03.362061] [D] [thread 2453030] This message should be displayed.. R> We note the easy-to-formatting in the source which benefits from the embedded fmt package for easy-to-use variable expansion. We also notice the different logging \"levels\" indicated by single letters: info , errror , warning , critical and debug . More on this below. Second example: Showcase This second example follows a more complete example in the spdlog documention and highlights numerous features of the library. As before, this example is also included in the RcppSpdlog package as examples/exampleTwo.cpp . And as before, do not use this example as a starting point in an R package. #include \"spdlog/spdlog.h\" #include void stdout_logger_example(); void basic_example(); void rotating_example(); void daily_example(); void async_example(); void binary_example(); void trace_example(); void multi_sink_example(); void user_defined_example(); void err_handler_example(); void syslog_example(); void clone_example(); #include \"spdlog/spdlog.h\" // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleTwo() { spdlog::info(\"Welcome to spdlog version {}.{}.{} !\", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:>8} aligned, {:<8} aligned\", \"right\", \"left\"); // Runtime log levels spdlog::set_level(spdlog::level::info); // Set global log level to info spdlog::debug(\"This message should not be displayed!\"); spdlog::set_level(spdlog::level::trace); // Set specific logger's log level spdlog::debug(\"This message should be displayed..\"); // Customize msg format for all loggers spdlog::set_pattern(\"[%H:%M:%S %z] [%^%L%$] [thread %t] %v\"); spdlog::info(\"This an info message with custom format\"); spdlog::set_pattern(\"%+\"); // back to default format try { stdout_logger_example(); basic_example(); rotating_example(); daily_example(); clone_example(); async_example(); binary_example(); multi_sink_example(); user_defined_example(); err_handler_example(); trace_example(); // Flush all *registered* loggers using a worker thread every 3 seconds. // note: registered loggers *must* be thread safe for this to work correctly! spdlog::flush_every(std::chrono::seconds(3)); // Apply some function on all registered loggers spdlog::apply_all([&](std::shared_ptr l) { l->info(\"End of example.\"); }); // Release all spdlog resources, and drop all loggers in the registry. // This is optional (only mandatory if using windows + async log). //spdlog::shutdown(); } // Exceptions will only be thrown upon failed logger or sink construction (not during logging). catch (const spdlog::spdlog_ex &ex) { std::printf(\"Log initialization failed: %s\\n\", ex.what()); return; } // added to this example file allow multiple runs of function spdlog::drop(\"console\"); spdlog::drop(\"file_logger\"); spdlog::drop(\"some_logger_name\"); spdlog::drop(\"daily_logger\"); spdlog::drop(\"async_file_logger\"); } #include \"spdlog/sinks/stdout_color_sinks.h\" // or #include \"spdlog/sinks/stdout_sinks.h\" if no colors needed. void stdout_logger_example() { // Create color multi threaded logger. auto console = spdlog::stdout_color_mt(\"console\"); // or for stderr: // auto console = spdlog::stderr_color_mt(\"error-logger\"); } #include \"spdlog/sinks/basic_file_sink.h\" void basic_example() { // Create basic file logger (not rotated). auto my_logger = spdlog::basic_logger_mt(\"file_logger\", \"logs/basic-log.txt\"); } #include \"spdlog/sinks/rotating_file_sink.h\" void rotating_example() { // Create a file rotating logger with 5mb size max and 3 rotated files. auto rotating_logger = spdlog::rotating_logger_mt(\"some_logger_name\", \"logs/rotating.txt\", 1048576 * 5, 3); } #include \"spdlog/sinks/daily_file_sink.h\" void daily_example() { // Create a daily logger - a new file is created every day on 2:30am. auto daily_logger = spdlog::daily_logger_mt(\"daily_logger\", \"logs/daily.txt\", 2, 30); } // Clone a logger and give it new name. // Useful for creating component/subsystem loggers from some \"root\" logger. void clone_example() { auto network_logger = spdlog::default_logger()->clone(\"network\"); network_logger->info(\"Logging network stuff..\"); } #include \"spdlog/async.h\" void async_example() { // Default thread pool settings can be modified *before* creating the async logger: // spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread. auto async_file = spdlog::basic_logger_mt(\"async_file_logger\", \"logs/async_log.txt\"); // alternatively: // auto async_file = // spdlog::create_async(\"async_file_logger\", // \"logs/async_log.txt\"); for (int i = 1; i < 101; ++i) { async_file->info(\"Async message #{}\", i); } } // Log binary data as hex. // Many types of std::container types can be used. // Iterator ranges are supported too. // Format flags: // {:X} - print in uppercase. // {:s} - don't separate each byte with space. // {:p} - don't print the position on each line start. // {:n} - don't split the output to lines. #include \"spdlog/fmt/bin_to_hex.h\" void binary_example() { std::vector buf; for (int i = 0; i < 80; i++) { buf.push_back(static_cast(i & 0xff)); } spdlog::info(\"Binary example: {}\", spdlog::to_hex(buf)); spdlog::info(\"Another binary example:{:n}\", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10)); // more examples: // logger->info(\"uppercase: {:X}\", spdlog::to_hex(buf)); // logger->info(\"uppercase, no delimiters: {:Xs}\", spdlog::to_hex(buf)); // logger->info(\"uppercase, no delimiters, no position info: {:Xsp}\", spdlog::to_hex(buf)); } // Compile time log levels. // define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE) void trace_example() { // trace from default logger SPDLOG_TRACE(\"Some trace message.. {} ,{}\", 1, 3.23); // debug from default logger SPDLOG_DEBUG(\"Some debug message.. {} ,{}\", 1, 3.23); // trace from logger object auto logger = spdlog::get(\"file_logger\"); SPDLOG_LOGGER_TRACE(logger, \"another trace message\"); } // A logger with multiple sinks (stdout and file) - each with a different format and log level. void multi_sink_example() { auto console_sink = std::make_shared(); console_sink->set_level(spdlog::level::warn); console_sink->set_pattern(\"[multi_sink_example] [%^%l%$] %v\"); auto file_sink = std::make_shared(\"logs/multisink.txt\", true); file_sink->set_level(spdlog::level::trace); spdlog::logger logger(\"multi_sink\", {console_sink, file_sink}); logger.set_level(spdlog::level::debug); logger.warn(\"this should appear in both console and file\"); logger.info(\"this message should not appear in the console, only in the file\"); } // User defined types logging by implementing operator<< #include \"spdlog/fmt/ostr.h\" // must be included struct my_type { int i; template friend OStream &operator<<(OStream &os, const my_type &c) { return os << \"[my_type i=\" << c.i << \"]\"; } }; void user_defined_example() { spdlog::info(\"user defined type: {}\", my_type{14}); } // Custom error handler. Will be triggered on log failure. void err_handler_example() { // can be set globally or per logger(logger->set_error_handler(..)) spdlog::set_error_handler([](const std::string &msg) { printf(\"*** Custom log error handler: %s ***\\n\", msg.c_str()); }); } // syslog example (linux/osx/freebsd) #ifndef _WIN32 #include \"spdlog/sinks/syslog_sink.h\" void syslog_example() { std::string ident = \"spdlog-example\"; auto syslog_logger = spdlog::syslog_logger_mt(\"syslog\", ident, LOG_PID); syslog_logger->warn(\"This is warning that will end up in syslog.\"); } #endif // Android example. #if defined(__ANDROID__) #include \"spdlog/sinks/android_sink.h\" void android_example() { std::string tag = \"spdlog-android\"; auto android_logger = spdlog::android_logger_mt(\"android\", tag); android_logger->critical(\"Use \\\"adb shell logcat\\\" to view this message.\"); } #endif /*** R exampleTwo() */ We are not showing the output here; it can be compiled, linked, loaded and run just as above by simply passing the filename to Rcpp::sourceCpp() . Note that is will create a few demonstration logfiles so you may want to run the example from a temporary directory. Third example: Colour The next example highlights a colour 'sink' for the logger. Again, do not use this as a starting point for your package as R CMD check will protest about use of stdout . #include \"spdlog/spdlog.h\" #include \"spdlog/sinks/stdout_color_sinks.h\" #include // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleThree() { auto console = spdlog::stdout_color_mt(\"console\"); // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%^%L%$] [thread %t] %v\"); spdlog::info(\"This an info message with custom format\"); //spdlog::set_pattern(\"%+\"); // back to default format spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); // added to this example file allow multiple runs of different package functions spdlog::drop(\"console\"); } /*** R exampleThree() */ When running this example in a terminal capable of displaying colour escape sequence, the logging levels are distinguished by colour. This ranges from green (\"info\") to yellow (\"warning\") to red (\"error\") and white-on-red (\"critical\"). Not that in this vignette color from standard output does how not show (in the keep-it-simple-mode we are using here). R> exampleThree() [14:47:52.260692] [I] [thread 2502026] This an info message with custom format [14:47:52.260715] [I] [thread 2502026] Welcome to spdlog! [14:47:52.260732] [E] [thread 2502026] Some error message with arg: 1 [14:47:52.260734] [W] [thread 2502026] Easy padding in numbers like 00000012 [14:47:52.260736] [C] [thread 2502026] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [14:47:52.260739] [I] [thread 2502026] Support for floats 1.23 [14:47:52.260741] [I] [thread 2502026] Positional args are supported too.. [14:47:52.260743] [I] [thread 2502026] left aligned R> Fourth Example: Dedicated R Logger The next example is suitable for use in R packages, and in fact included as an example in the package. We include the source file src/exampleRsink.cpp . // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include #include // also support stopwatch feature //' spdlog Example using a sink for R //' //' A simple example invoking a derived R/Rcpp logger. Also demonstrates the //' stopwatch feature. For more features see the 'spdlog' documnetation. //' //' Note that this no longer triggers R warnings thanks to excellent help by //' Gabi Melman. //' @return None //' @examples //' exampleRsink() // [[Rcpp::export]] void exampleRsink() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed spdlog::set_default_logger(sp); // and set as default spdlog::stopwatch sw; // instantiate a stop watch // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::info(\"Elapsed time: {}\", sw); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::info(\"Elapsed time: {}\", sw); } //' spdlog Logging Lever Setter //' //' A helper function to turn a logging level given as string //' into the current logging level //' //' @param name A string with the logging level. Value understood are, //' in decreasing verbosity \\sQuote{trace}, \\sQuote{debug}, \\sQuote{info}, //' \\sQuote{warning}, \\sQuote{error}, \\sQuote{critical}, and \\sQuote{off}. //' Unrecognised names are equivalent to \\sQuote{off}. //' @return Nothing is returned. // [[Rcpp::export]] void setLogLevel(const std::string &name) { spdlog::set_level(spdlog::level::from_str(name)); } The example file contains three key aspects to highlight: - use of the r_sink_mt() class for R-specific logger sink - use of the very convenient stopwatch object - use of logging levels We highlight these below after first showing the relevant output: R> exampleRsink() [16:52:12.076751] [fromR] [I] [thread 2453030] Welcome to spdlog! [16:52:12.076809] [fromR] [E] [thread 2453030] Some error message with arg: 1 [16:52:12.076823] [fromR] [I] [thread 2453030] Elapsed time: 9.6104e-05 [16:52:12.076833] [fromR] [W] [thread 2453030] Easy padding in numbers like 00000012 [16:52:12.076844] [fromR] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [16:52:12.076853] [fromR] [I] [thread 2453030] Support for floats 1.23 [16:52:12.076871] [fromR] [I] [thread 2453030] Positional args are supported too.. [16:52:12.076879] [fromR] [I] [thread 2453030] left aligned [16:52:12.076892] [fromR] [I] [thread 2453030] Elapsed time: 0.000167057 R> R-specific sink spdlog has the ability to derive and sub-class sinks for logger. The RcppSpdlog package uses this feature to implement a sink using the Rcpp conduit Rcpp::Rcout instead of std::cout as it conveniently redirects to the R output stream. This class should be the default one for any R packages wanting to use spdlog while also passing R CMD check . A second important aspect of the initial code in function exampleRsink() is how a named logging instance is requested. If none is found, a new one is instantiated. Next, this logger is made the default logger permitting convenient programmatic access via spdlog:: . Stopwatch A powerful (recent) feature of the include fmt library is the automatic formatting of timestamps and interval. As the code example shows, simply instantianting an object, here called sw , and referring to it later is all that takes. Log-Level A second utility function setLogLevel() is also provided. Usage is simple: after calling it with a given level, only message equal to it or higher are shown as the next example shows. R> setLogLevel(\"error\") R> exampleRsink() [16:54:12.666261] [fromR] [E] [thread 2453030] Some error message with arg: 1 [16:54:12.666286] [fromR] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 R> By requestion level 'error', message of level 'info', 'warning' or 'debug' are suppressed but messages levels 'error' or 'critical' as shown as desired. Fifth Example: Initialization Package desiring to use RcppSpdlog can initialize its facilities during startup. For that we first define a setup function // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include //' Set a new default logger for R //' // [[Rcpp::export]] void setDefault() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed sp->set_pattern(\"[%H:%M:%S.%f] [%^%L%$] %v\"); spdlog::set_default_logger(sp); } We can then call this function during startup: .onLoad <- function(libname, pkgname) { setDefault(); } Sixth Example: Compile-time Selection Of course, spdlog also supports a common usage paradigm with loggers in which the decision of whether to log or not is compile-time rather than run time. As this is typically implemented via macros, usage is via upper-case macros as well. The following example shows a function with three different logging-level statements as well as a #define set such one and only one is shown. Similarly, code can contain debug or trace or info or ... statements which would not appear in the actually loaded \"production code\" (or CRAN version) if the compile-time logging level define is set high enough. // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include // A define such as this could also be set in src/Makevars via a -D flag #define SPDLOG_LOG_LEVEL SPDLOG_LEVEL_CRITICAL // [[Rcpp::export]] void demoInvisible() { Rcpp::Rcout << \"Hello from demoInvisible, just to show we're being called...\\n\"; // trace message via default logger SPDLOG_TRACE(\"Some trace message.. {} ,{}\", 1, 3.23); // debug message via default logger SPDLOG_DEBUG(\"Some debug message.. {} ,{}\", 1, 3.23); // debug message via default logger SPDLOG_CRITICAL(\"Some critical message.. {} ,{}\", 1, 3.23); } When a piece of code with such compile-time defines is used, we see the expected outcome. The following example uses default logger, and as the preceding section showed this can be set up to be the custom R sink: R> Rcpp::sourceCpp(\"/tmp/rcppspdlog.cpp\") # plus a '// [[Rcpp:depends(\"RcppSpdlog\")' R> demoInvisible() Hello from demoInvisible, just to show we're being called... [08:44:48.198075] [fromR] [C] [thread 2453030] Some critical message.. 1 ,3.23 R> Seventh Example: Access From R As of package 0.0.9, RcppSpdlog supports two new modes. The first is direct logging support from R and described in this section; the second is access from another R package and described thereafter. A number of basic functions are exported using Rcpp. These include log_setup(name, level) to instantiate a named logger at a given level (instead of an unnamed default at level 'warn'), log_filesetup(filename, name, level) (same using the named file as logging destination), a helper log_drop(name) to drop a named logger, two setters log_set_pattern() and log_set_level() to set, respectively, the displayed log pattern and the level. This is complemented by the actual loggers ranging from log_trace() and log_debug() to log_info() , log_warn() , log_error() and finally log_critical() . The following example (also the example in the manual page) illustrates. > library(RcppSpdlog) > log_setup(\"demo\") # default level 'warn' is used > log_info(\"this message is NOT seen\") > log_set_level(\"debug\") > log_set_pattern(\"%^[%H:%M:%S.%e] [%n] [%l] %v%$\") # set a pattern w/o process id > log_info(\"this message is seen\") [15:55:34.150] [demo] [info] this message is seen > log_warn(\"as is this message\") [ 15:55:37.513] [demo] [warning] as is this message > The interface expects a character value so use from either sprintf() or a string-interpolating helper such as glue::glue can be used: > log_info(sprintf(\"We can %s a %s with values %d\", \"build\", \"text\", 42L)) [16:03:37.728] [demo] [info] We can build a text with values 42 > log_info(glue::glue(\"We can {a} a {b} with values {v}\", a=\"build\", b=\"text\", v=42L)) [16:03:46.395] [demo] [info] We can build a text with values 42 > Eight Example: Access From Another R Package As of package 0.0.9, another package can use the C++ level functions (either with or without the R functions) by importing the RcppSpdlog while ensuring at least one function from the package is imported (so that the C-level interface functions are instantiated by R). This is time-honoured mechanism long-used by lme4 to access (compiled) functions from Matrix as well as by xts to access code from zoo , and others. To properly import the package, add just one import, for example importFrom((RcppSpdlog, log_setup) to the NAMESPACE file of your package, along with the required Imports: RcppSpdlog in the DESCRIPTION file. The available functions are the same as the ones described in the previous section, but now available at the C++ level in the RcppSpdlog namespace. So for example #include RcppSpdlog::log_setup(\"demoLogger\", \"info\"); // create logger at info level RcppSpdlog::log_info(\"logger created\"); will work. Nineth Example: More compact C++ Access As the (auto-generated, thanks to Rcpp ) interface described in the previous section is a little \"wordy\", we added a simple aliasing wrapping in a new namespace spdl and, given the protection from naming collisions offered by the namespace, shortened the accessor function names. So the previous example can also be used via #include spdl::setup(\"demoLogger\", \"info\"); // create logger at info level spdl::info(\"logger created\"); The logger interface takes a simple string. Two easy options exist for formatting such as string. First, one can rely on the tinyformat version included with Rcpp and use tfm::format() which works with standard printf() operators. Second, one can use the fmt library included with spdlog via an explicit call. # using tfm::format spdl::info(tfm::format(\"We %s values %d and %f\", \"log\", 42, 1.23)); # using fmt::format spdl::info(fmt::format(\"We {} values {} and {}\", \"log\", 42, 1.23)); Here both formatters have to be called explicitly as we use a simple one-function signature (per logging function) to the underlying C language implementation without the fuller flexibility of variadic arguments. As C++11 can be assumed, we can also offers a variadic template expansion for fmt::format() and the second example simply becomes spdl::info(\"We {} values {} and {}\", \"log\", 42, 1.23); Tenth Example: More compact R Access As the more compact access in the previous section is quite compelling we also created a sibbling R package spd providing a spdl namespace in R allowing _the exact same format strings too`. So spdl::info(\"We {} values {} and {}\", \"log\", 42L, 1.23); now also works from R using the same formatting string. We inted to upload spdl to CRAN too. Note that other all other formatting options are supported from R: the first argument is a character variable which can be constructed using paste , sprintf , or any of the string-interpolating packages. But as none of those methods works like fmt (which we have come to like a lot) we added support for it too. Conclusion spdlog and the included fmt are two very powerful and widely used C++ libraries. The RcppSpdlog package adds to them to the set of packages R users can deploy. The spd package makes access even easier and more consistent. It is our hope that the examples shown here are of interest to R users who are looking for effortless, performant and flexible logging solutions for their R packages.","title":"Introduction"},{"location":"vignette/introduction/#introducing-rcppspdlog","text":"spdlog is a widely-used and very capable header-only C++ library for logging. The RcppSpdlog package provides R users with easy-to-use customized access to the spdlog logging library by including its headers in an R package which permit other R packages to deploy it via a simple LinkingTo: RcppSpdlog as described in Section 1.1.3 of WRE . spdlog is mature and widely deployed. It also has a very rich set of features described at the repository wiki . This vignette will highlight a few first use cases. Note that in order to use RcppSpdlog in an R package that might get distributed to CRAN , the code should follow the example R and C++ code in function exampleRsink() as described below. We will however start with some simpler examples. Do not copy those into your R package. The package checks used by R test for use of stdout and stderr which is why the customized setup described later is preferable.","title":"Introducing RcppSpdlog"},{"location":"vignette/introduction/#initial-example-basics","text":"This example follows the simplest and initial example in the spdlog . It is also included in the RcppSpdlog package as examples/exampleOne.cpp . As discussed above, do not use this example as a starting point in an R package. // based on the 'basic usage' example in the README.md at https://github.com/gabime/spdlog #include \"spdlog/spdlog.h\" #include // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleOne() { // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%L] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::set_level(spdlog::level::debug); // Set global log level to debug spdlog::debug(\"This message should be displayed..\"); // Compile time log levels // define SPDLOG_ACTIVE_LEVEL to desired level SPDLOG_TRACE(\"Some trace message with param {}\", {}); SPDLOG_DEBUG(\"Some debug message\"); } /*** R exampleOne() */ When built, which is easiest via Rcpp::sourceCpp() , the final block ensures that the created function exampleOne() is executed. In one previous run, the following output was produded: R> exampleOne() [14:25:03.362024] [I] [thread 2453030] Welcome to spdlog! [14:25:03.362047] [E] [thread 2453030] Some error message with arg: 1 [14:25:03.362051] [W] [thread 2453030] Easy padding in numbers like 00000012 [14:25:03.362053] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [14:25:03.362056] [I] [thread 2453030] Support for floats 1.23 [14:25:03.362058] [I] [thread 2453030] Positional args are supported too.. [14:25:03.362060] [I] [thread 2453030] left aligned [14:25:03.362061] [D] [thread 2453030] This message should be displayed.. R> We note the easy-to-formatting in the source which benefits from the embedded fmt package for easy-to-use variable expansion. We also notice the different logging \"levels\" indicated by single letters: info , errror , warning , critical and debug . More on this below.","title":"Initial example: Basics"},{"location":"vignette/introduction/#second-example-showcase","text":"This second example follows a more complete example in the spdlog documention and highlights numerous features of the library. As before, this example is also included in the RcppSpdlog package as examples/exampleTwo.cpp . And as before, do not use this example as a starting point in an R package. #include \"spdlog/spdlog.h\" #include void stdout_logger_example(); void basic_example(); void rotating_example(); void daily_example(); void async_example(); void binary_example(); void trace_example(); void multi_sink_example(); void user_defined_example(); void err_handler_example(); void syslog_example(); void clone_example(); #include \"spdlog/spdlog.h\" // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleTwo() { spdlog::info(\"Welcome to spdlog version {}.{}.{} !\", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:>8} aligned, {:<8} aligned\", \"right\", \"left\"); // Runtime log levels spdlog::set_level(spdlog::level::info); // Set global log level to info spdlog::debug(\"This message should not be displayed!\"); spdlog::set_level(spdlog::level::trace); // Set specific logger's log level spdlog::debug(\"This message should be displayed..\"); // Customize msg format for all loggers spdlog::set_pattern(\"[%H:%M:%S %z] [%^%L%$] [thread %t] %v\"); spdlog::info(\"This an info message with custom format\"); spdlog::set_pattern(\"%+\"); // back to default format try { stdout_logger_example(); basic_example(); rotating_example(); daily_example(); clone_example(); async_example(); binary_example(); multi_sink_example(); user_defined_example(); err_handler_example(); trace_example(); // Flush all *registered* loggers using a worker thread every 3 seconds. // note: registered loggers *must* be thread safe for this to work correctly! spdlog::flush_every(std::chrono::seconds(3)); // Apply some function on all registered loggers spdlog::apply_all([&](std::shared_ptr l) { l->info(\"End of example.\"); }); // Release all spdlog resources, and drop all loggers in the registry. // This is optional (only mandatory if using windows + async log). //spdlog::shutdown(); } // Exceptions will only be thrown upon failed logger or sink construction (not during logging). catch (const spdlog::spdlog_ex &ex) { std::printf(\"Log initialization failed: %s\\n\", ex.what()); return; } // added to this example file allow multiple runs of function spdlog::drop(\"console\"); spdlog::drop(\"file_logger\"); spdlog::drop(\"some_logger_name\"); spdlog::drop(\"daily_logger\"); spdlog::drop(\"async_file_logger\"); } #include \"spdlog/sinks/stdout_color_sinks.h\" // or #include \"spdlog/sinks/stdout_sinks.h\" if no colors needed. void stdout_logger_example() { // Create color multi threaded logger. auto console = spdlog::stdout_color_mt(\"console\"); // or for stderr: // auto console = spdlog::stderr_color_mt(\"error-logger\"); } #include \"spdlog/sinks/basic_file_sink.h\" void basic_example() { // Create basic file logger (not rotated). auto my_logger = spdlog::basic_logger_mt(\"file_logger\", \"logs/basic-log.txt\"); } #include \"spdlog/sinks/rotating_file_sink.h\" void rotating_example() { // Create a file rotating logger with 5mb size max and 3 rotated files. auto rotating_logger = spdlog::rotating_logger_mt(\"some_logger_name\", \"logs/rotating.txt\", 1048576 * 5, 3); } #include \"spdlog/sinks/daily_file_sink.h\" void daily_example() { // Create a daily logger - a new file is created every day on 2:30am. auto daily_logger = spdlog::daily_logger_mt(\"daily_logger\", \"logs/daily.txt\", 2, 30); } // Clone a logger and give it new name. // Useful for creating component/subsystem loggers from some \"root\" logger. void clone_example() { auto network_logger = spdlog::default_logger()->clone(\"network\"); network_logger->info(\"Logging network stuff..\"); } #include \"spdlog/async.h\" void async_example() { // Default thread pool settings can be modified *before* creating the async logger: // spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread. auto async_file = spdlog::basic_logger_mt(\"async_file_logger\", \"logs/async_log.txt\"); // alternatively: // auto async_file = // spdlog::create_async(\"async_file_logger\", // \"logs/async_log.txt\"); for (int i = 1; i < 101; ++i) { async_file->info(\"Async message #{}\", i); } } // Log binary data as hex. // Many types of std::container types can be used. // Iterator ranges are supported too. // Format flags: // {:X} - print in uppercase. // {:s} - don't separate each byte with space. // {:p} - don't print the position on each line start. // {:n} - don't split the output to lines. #include \"spdlog/fmt/bin_to_hex.h\" void binary_example() { std::vector buf; for (int i = 0; i < 80; i++) { buf.push_back(static_cast(i & 0xff)); } spdlog::info(\"Binary example: {}\", spdlog::to_hex(buf)); spdlog::info(\"Another binary example:{:n}\", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10)); // more examples: // logger->info(\"uppercase: {:X}\", spdlog::to_hex(buf)); // logger->info(\"uppercase, no delimiters: {:Xs}\", spdlog::to_hex(buf)); // logger->info(\"uppercase, no delimiters, no position info: {:Xsp}\", spdlog::to_hex(buf)); } // Compile time log levels. // define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE) void trace_example() { // trace from default logger SPDLOG_TRACE(\"Some trace message.. {} ,{}\", 1, 3.23); // debug from default logger SPDLOG_DEBUG(\"Some debug message.. {} ,{}\", 1, 3.23); // trace from logger object auto logger = spdlog::get(\"file_logger\"); SPDLOG_LOGGER_TRACE(logger, \"another trace message\"); } // A logger with multiple sinks (stdout and file) - each with a different format and log level. void multi_sink_example() { auto console_sink = std::make_shared(); console_sink->set_level(spdlog::level::warn); console_sink->set_pattern(\"[multi_sink_example] [%^%l%$] %v\"); auto file_sink = std::make_shared(\"logs/multisink.txt\", true); file_sink->set_level(spdlog::level::trace); spdlog::logger logger(\"multi_sink\", {console_sink, file_sink}); logger.set_level(spdlog::level::debug); logger.warn(\"this should appear in both console and file\"); logger.info(\"this message should not appear in the console, only in the file\"); } // User defined types logging by implementing operator<< #include \"spdlog/fmt/ostr.h\" // must be included struct my_type { int i; template friend OStream &operator<<(OStream &os, const my_type &c) { return os << \"[my_type i=\" << c.i << \"]\"; } }; void user_defined_example() { spdlog::info(\"user defined type: {}\", my_type{14}); } // Custom error handler. Will be triggered on log failure. void err_handler_example() { // can be set globally or per logger(logger->set_error_handler(..)) spdlog::set_error_handler([](const std::string &msg) { printf(\"*** Custom log error handler: %s ***\\n\", msg.c_str()); }); } // syslog example (linux/osx/freebsd) #ifndef _WIN32 #include \"spdlog/sinks/syslog_sink.h\" void syslog_example() { std::string ident = \"spdlog-example\"; auto syslog_logger = spdlog::syslog_logger_mt(\"syslog\", ident, LOG_PID); syslog_logger->warn(\"This is warning that will end up in syslog.\"); } #endif // Android example. #if defined(__ANDROID__) #include \"spdlog/sinks/android_sink.h\" void android_example() { std::string tag = \"spdlog-android\"; auto android_logger = spdlog::android_logger_mt(\"android\", tag); android_logger->critical(\"Use \\\"adb shell logcat\\\" to view this message.\"); } #endif /*** R exampleTwo() */ We are not showing the output here; it can be compiled, linked, loaded and run just as above by simply passing the filename to Rcpp::sourceCpp() . Note that is will create a few demonstration logfiles so you may want to run the example from a temporary directory.","title":"Second example: Showcase"},{"location":"vignette/introduction/#third-example-colour","text":"The next example highlights a colour 'sink' for the logger. Again, do not use this as a starting point for your package as R CMD check will protest about use of stdout . #include \"spdlog/spdlog.h\" #include \"spdlog/sinks/stdout_color_sinks.h\" #include // [[Rcpp::depends(RcppSpdlog)]] // [[Rcpp::export]] void exampleThree() { auto console = spdlog::stdout_color_mt(\"console\"); // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%^%L%$] [thread %t] %v\"); spdlog::info(\"This an info message with custom format\"); //spdlog::set_pattern(\"%+\"); // back to default format spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); // added to this example file allow multiple runs of different package functions spdlog::drop(\"console\"); } /*** R exampleThree() */ When running this example in a terminal capable of displaying colour escape sequence, the logging levels are distinguished by colour. This ranges from green (\"info\") to yellow (\"warning\") to red (\"error\") and white-on-red (\"critical\"). Not that in this vignette color from standard output does how not show (in the keep-it-simple-mode we are using here). R> exampleThree() [14:47:52.260692] [I] [thread 2502026] This an info message with custom format [14:47:52.260715] [I] [thread 2502026] Welcome to spdlog! [14:47:52.260732] [E] [thread 2502026] Some error message with arg: 1 [14:47:52.260734] [W] [thread 2502026] Easy padding in numbers like 00000012 [14:47:52.260736] [C] [thread 2502026] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [14:47:52.260739] [I] [thread 2502026] Support for floats 1.23 [14:47:52.260741] [I] [thread 2502026] Positional args are supported too.. [14:47:52.260743] [I] [thread 2502026] left aligned R>","title":"Third example: Colour"},{"location":"vignette/introduction/#fourth-example-dedicated-r-logger","text":"The next example is suitable for use in R packages, and in fact included as an example in the package. We include the source file src/exampleRsink.cpp . // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include #include // also support stopwatch feature //' spdlog Example using a sink for R //' //' A simple example invoking a derived R/Rcpp logger. Also demonstrates the //' stopwatch feature. For more features see the 'spdlog' documnetation. //' //' Note that this no longer triggers R warnings thanks to excellent help by //' Gabi Melman. //' @return None //' @examples //' exampleRsink() // [[Rcpp::export]] void exampleRsink() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed spdlog::set_default_logger(sp); // and set as default spdlog::stopwatch sw; // instantiate a stop watch // change log pattern (changed from [%H:%M:%S %z] [%n] [%^---%L---%$] ) spdlog::set_pattern(\"[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v\"); spdlog::info(\"Welcome to spdlog!\"); spdlog::error(\"Some error message with arg: {}\", 1); spdlog::info(\"Elapsed time: {}\", sw); spdlog::warn(\"Easy padding in numbers like {:08d}\", 12); spdlog::critical(\"Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}\", 42); spdlog::info(\"Support for floats {:03.2f}\", 1.23456); spdlog::info(\"Positional args are {1} {0}..\", \"too\", \"supported\"); spdlog::info(\"{:<30}\", \"left aligned\"); spdlog::info(\"Elapsed time: {}\", sw); } //' spdlog Logging Lever Setter //' //' A helper function to turn a logging level given as string //' into the current logging level //' //' @param name A string with the logging level. Value understood are, //' in decreasing verbosity \\sQuote{trace}, \\sQuote{debug}, \\sQuote{info}, //' \\sQuote{warning}, \\sQuote{error}, \\sQuote{critical}, and \\sQuote{off}. //' Unrecognised names are equivalent to \\sQuote{off}. //' @return Nothing is returned. // [[Rcpp::export]] void setLogLevel(const std::string &name) { spdlog::set_level(spdlog::level::from_str(name)); } The example file contains three key aspects to highlight: - use of the r_sink_mt() class for R-specific logger sink - use of the very convenient stopwatch object - use of logging levels We highlight these below after first showing the relevant output: R> exampleRsink() [16:52:12.076751] [fromR] [I] [thread 2453030] Welcome to spdlog! [16:52:12.076809] [fromR] [E] [thread 2453030] Some error message with arg: 1 [16:52:12.076823] [fromR] [I] [thread 2453030] Elapsed time: 9.6104e-05 [16:52:12.076833] [fromR] [W] [thread 2453030] Easy padding in numbers like 00000012 [16:52:12.076844] [fromR] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [16:52:12.076853] [fromR] [I] [thread 2453030] Support for floats 1.23 [16:52:12.076871] [fromR] [I] [thread 2453030] Positional args are supported too.. [16:52:12.076879] [fromR] [I] [thread 2453030] left aligned [16:52:12.076892] [fromR] [I] [thread 2453030] Elapsed time: 0.000167057 R>","title":"Fourth Example: Dedicated R Logger"},{"location":"vignette/introduction/#r-specific-sink","text":"spdlog has the ability to derive and sub-class sinks for logger. The RcppSpdlog package uses this feature to implement a sink using the Rcpp conduit Rcpp::Rcout instead of std::cout as it conveniently redirects to the R output stream. This class should be the default one for any R packages wanting to use spdlog while also passing R CMD check . A second important aspect of the initial code in function exampleRsink() is how a named logging instance is requested. If none is found, a new one is instantiated. Next, this logger is made the default logger permitting convenient programmatic access via spdlog:: .","title":"R-specific sink"},{"location":"vignette/introduction/#stopwatch","text":"A powerful (recent) feature of the include fmt library is the automatic formatting of timestamps and interval. As the code example shows, simply instantianting an object, here called sw , and referring to it later is all that takes.","title":"Stopwatch"},{"location":"vignette/introduction/#log-level","text":"A second utility function setLogLevel() is also provided. Usage is simple: after calling it with a given level, only message equal to it or higher are shown as the next example shows. R> setLogLevel(\"error\") R> exampleRsink() [16:54:12.666261] [fromR] [E] [thread 2453030] Some error message with arg: 1 [16:54:12.666286] [fromR] [C] [thread 2453030] Support for int: 42; hex: 2a; oct: 52; bin: 101010 R> By requestion level 'error', message of level 'info', 'warning' or 'debug' are suppressed but messages levels 'error' or 'critical' as shown as desired.","title":"Log-Level"},{"location":"vignette/introduction/#fifth-example-initialization","text":"Package desiring to use RcppSpdlog can initialize its facilities during startup. For that we first define a setup function // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include //' Set a new default logger for R //' // [[Rcpp::export]] void setDefault() { std::string logname = \"fromR\"; // fix a name for this logger auto sp = spdlog::get(logname); // retrieve existing one if (sp == nullptr) sp = spdlog::r_sink_mt(logname); // or create new one if needed sp->set_pattern(\"[%H:%M:%S.%f] [%^%L%$] %v\"); spdlog::set_default_logger(sp); } We can then call this function during startup: .onLoad <- function(libname, pkgname) { setDefault(); }","title":"Fifth Example: Initialization"},{"location":"vignette/introduction/#sixth-example-compile-time-selection","text":"Of course, spdlog also supports a common usage paradigm with loggers in which the decision of whether to log or not is compile-time rather than run time. As this is typically implemented via macros, usage is via upper-case macros as well. The following example shows a function with three different logging-level statements as well as a #define set such one and only one is shown. Similarly, code can contain debug or trace or info or ... statements which would not appear in the actually loaded \"production code\" (or CRAN version) if the compile-time logging level define is set high enough. // this portmanteau include also defines the r_sink we use below, and which // diverts all logging to R via the Rcpp::Rcout replacement for std::cout #include // A define such as this could also be set in src/Makevars via a -D flag #define SPDLOG_LOG_LEVEL SPDLOG_LEVEL_CRITICAL // [[Rcpp::export]] void demoInvisible() { Rcpp::Rcout << \"Hello from demoInvisible, just to show we're being called...\\n\"; // trace message via default logger SPDLOG_TRACE(\"Some trace message.. {} ,{}\", 1, 3.23); // debug message via default logger SPDLOG_DEBUG(\"Some debug message.. {} ,{}\", 1, 3.23); // debug message via default logger SPDLOG_CRITICAL(\"Some critical message.. {} ,{}\", 1, 3.23); } When a piece of code with such compile-time defines is used, we see the expected outcome. The following example uses default logger, and as the preceding section showed this can be set up to be the custom R sink: R> Rcpp::sourceCpp(\"/tmp/rcppspdlog.cpp\") # plus a '// [[Rcpp:depends(\"RcppSpdlog\")' R> demoInvisible() Hello from demoInvisible, just to show we're being called... [08:44:48.198075] [fromR] [C] [thread 2453030] Some critical message.. 1 ,3.23 R>","title":"Sixth Example: Compile-time Selection"},{"location":"vignette/introduction/#seventh-example-access-from-r","text":"As of package 0.0.9, RcppSpdlog supports two new modes. The first is direct logging support from R and described in this section; the second is access from another R package and described thereafter. A number of basic functions are exported using Rcpp. These include log_setup(name, level) to instantiate a named logger at a given level (instead of an unnamed default at level 'warn'), log_filesetup(filename, name, level) (same using the named file as logging destination), a helper log_drop(name) to drop a named logger, two setters log_set_pattern() and log_set_level() to set, respectively, the displayed log pattern and the level. This is complemented by the actual loggers ranging from log_trace() and log_debug() to log_info() , log_warn() , log_error() and finally log_critical() . The following example (also the example in the manual page) illustrates. > library(RcppSpdlog) > log_setup(\"demo\") # default level 'warn' is used > log_info(\"this message is NOT seen\") > log_set_level(\"debug\") > log_set_pattern(\"%^[%H:%M:%S.%e] [%n] [%l] %v%$\") # set a pattern w/o process id > log_info(\"this message is seen\") [15:55:34.150] [demo] [info] this message is seen > log_warn(\"as is this message\") [ 15:55:37.513] [demo] [warning] as is this message > The interface expects a character value so use from either sprintf() or a string-interpolating helper such as glue::glue can be used: > log_info(sprintf(\"We can %s a %s with values %d\", \"build\", \"text\", 42L)) [16:03:37.728] [demo] [info] We can build a text with values 42 > log_info(glue::glue(\"We can {a} a {b} with values {v}\", a=\"build\", b=\"text\", v=42L)) [16:03:46.395] [demo] [info] We can build a text with values 42 >","title":"Seventh Example: Access From R"},{"location":"vignette/introduction/#eight-example-access-from-another-r-package","text":"As of package 0.0.9, another package can use the C++ level functions (either with or without the R functions) by importing the RcppSpdlog while ensuring at least one function from the package is imported (so that the C-level interface functions are instantiated by R). This is time-honoured mechanism long-used by lme4 to access (compiled) functions from Matrix as well as by xts to access code from zoo , and others. To properly import the package, add just one import, for example importFrom((RcppSpdlog, log_setup) to the NAMESPACE file of your package, along with the required Imports: RcppSpdlog in the DESCRIPTION file. The available functions are the same as the ones described in the previous section, but now available at the C++ level in the RcppSpdlog namespace. So for example #include RcppSpdlog::log_setup(\"demoLogger\", \"info\"); // create logger at info level RcppSpdlog::log_info(\"logger created\"); will work.","title":"Eight Example: Access From Another R Package"},{"location":"vignette/introduction/#nineth-example-more-compact-c-access","text":"As the (auto-generated, thanks to Rcpp ) interface described in the previous section is a little \"wordy\", we added a simple aliasing wrapping in a new namespace spdl and, given the protection from naming collisions offered by the namespace, shortened the accessor function names. So the previous example can also be used via #include spdl::setup(\"demoLogger\", \"info\"); // create logger at info level spdl::info(\"logger created\"); The logger interface takes a simple string. Two easy options exist for formatting such as string. First, one can rely on the tinyformat version included with Rcpp and use tfm::format() which works with standard printf() operators. Second, one can use the fmt library included with spdlog via an explicit call. # using tfm::format spdl::info(tfm::format(\"We %s values %d and %f\", \"log\", 42, 1.23)); # using fmt::format spdl::info(fmt::format(\"We {} values {} and {}\", \"log\", 42, 1.23)); Here both formatters have to be called explicitly as we use a simple one-function signature (per logging function) to the underlying C language implementation without the fuller flexibility of variadic arguments. As C++11 can be assumed, we can also offers a variadic template expansion for fmt::format() and the second example simply becomes spdl::info(\"We {} values {} and {}\", \"log\", 42, 1.23);","title":"Nineth Example: More compact C++ Access"},{"location":"vignette/introduction/#tenth-example-more-compact-r-access","text":"As the more compact access in the previous section is quite compelling we also created a sibbling R package spd providing a spdl namespace in R allowing _the exact same format strings too`. So spdl::info(\"We {} values {} and {}\", \"log\", 42L, 1.23); now also works from R using the same formatting string. We inted to upload spdl to CRAN too. Note that other all other formatting options are supported from R: the first argument is a character variable which can be constructed using paste , sprintf , or any of the string-interpolating packages. But as none of those methods works like fmt (which we have come to like a lot) we added support for it too.","title":"Tenth Example: More compact R Access"},{"location":"vignette/introduction/#conclusion","text":"spdlog and the included fmt are two very powerful and widely used C++ libraries. The RcppSpdlog package adds to them to the set of packages R users can deploy. The spd package makes access even easier and more consistent. It is our hope that the examples shown here are of interest to R users who are looking for effortless, performant and flexible logging solutions for their R packages.","title":"Conclusion"}]} \ No newline at end of file diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 398cf97..8bf5b2e 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -2,52 +2,52 @@ https://github.com/eddelbuettel/rcppspdlog/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/changelog/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/news/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/man/RcppSpdlog-package/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/man/exampleRsink/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/man/formatter/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/man/get_stopwatch/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/man/log_setup/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/man/setLogLevel/ - 2024-01-12 + 2024-04-26 daily https://github.com/eddelbuettel/rcppspdlog/vignette/introduction/ - 2024-01-12 + 2024-04-26 daily \ No newline at end of file diff --git a/docs/sitemap.xml.gz b/docs/sitemap.xml.gz index 858d96e..11c4e50 100644 Binary files a/docs/sitemap.xml.gz and b/docs/sitemap.xml.gz differ diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 8aed1fe..852f07a 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -6,13 +6,13 @@ \section{Changes in RcppSpdlog version 0.0.17 (2024-04-25)}{ \itemize{ \item Minor continuous integration update - \item Upgraded to upstream releases spdlog 1.14.0 + \item Upgraded to upstream release spdlog 1.14.0 } } \section{Changes in RcppSpdlog version 0.0.16 (2024-01-12)}{ \itemize{ - \item Upgraded to upstream releases spdlog 1.13.0 + \item Upgraded to upstream release spdlog 1.13.0 } } @@ -27,7 +27,7 @@ \section{Changes in RcppSpdlog version 0.0.14 (2023-07-09)}{ \itemize{ \item Added new badge to README.md - \item Upgraded to upstream releases spdlog 1.12.0 + \item Upgraded to upstream release spdlog 1.12.0 } } @@ -73,13 +73,13 @@ \item Add both an R and an C++ interface to \code{spdlog} \item Update GitHub Actions to checkout@v3 \item Add a shorter aliased namespace for C++ - \item Upgraded to upstream releases spdlog 1.11.0 + \item Upgraded to upstream release spdlog 1.11.0 } } \section{Changes in RcppSpdlog version 0.0.8 (2022-04-04)}{ \itemize{ - \item Upgraded to upstream releases spdlog 1.10.0 + \item Upgraded to upstream release spdlog 1.10.0 } }