Writes a log message, suitable for use inside pipes, meaning that the first
argument is passed through untouched. The log message is processed using
glue::glue, and you can reference the incoming data as .data
inside the
log message.
logger(.data = NULL, msg = "", level = "INFO")
.data | This argument is returned as-is. |
---|---|
msg | The log message, processed using glue::glue. You can refernce
the data passed in via |
level | The log level, default is "INFO" and possible values include "DEBUG", "INFO", "WARNING", "ERROR", and "FATAL". |
You can set the maximum debug level and the log output locations using the
global options grkmisc.log_level
and grkmisc.log_output
. The defaults
are "INFO"
and stdout()
respectively.
library(dplyr) iris %>% logger("Starting with {nrow(.data)} rows") %>% filter(Species == "setosa") %>% logger("Filtered to {nrow(.data)} rows and {ncol(.data)} columns") %>% head()#> [2020-02-18 21:30:05.473995] INFO Starting with 150 rows #> [2020-02-18 21:30:05.475271] INFO Filtered to 50 rows and 5 columns#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa