The Anatomy of a Log Request

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(logger)
log_appender(appender_stdout)
knitr::include_graphics("logger_structure.svg")

To make a successful log record, logger requires the below components:

Putting all these together (by explicitly setting the default config in the global namespace):

log_threshold(INFO)
log_formatter(formatter_glue)
log_layout(layout_simple)
log_appender(appender_stdout)
log_debug("I am a low level log message that will not be printed with a high log level threshold")
log_warn("I am a higher level log message that is very likely to be printed")

Note, that all logger definitions and requests are tied to a logging namespace, and one log request might trigger multiple logger definitions as well (stacking). Find more information on these in the Customizing the format and destination of log records vignette.

logger:::namespaces_reset()


Try the logger package in your browser

Any scripts or data that you put into this service are public.

logger documentation built on Oct. 30, 2024, 9:24 a.m.