log4r Basics

  • {log4r} vs {base} vs {cli}
    • {base} message/warning/error have least structure.
    • {cli} adds structure for human readability.
    • {log4r} adds structure that’s useful for a stream of events (timestamp, etc)
  • The object created via logger() defines where things go & how they look.
library(log4r)
log <- logger(threshold = "INFO", appenders = console_appender()) # Defaults

info(log, "Log starting.")
warn(log, "This is a warning!")
error(log, "This is an error, but not an R error.")
debug(log, "This won't show up.")
## INFO  [2022-12-03 10:31:41] Log starting.
## WARN  [2022-12-03 10:31:41] This is a warning!
## ERROR [2022-12-03 10:31:41] This is an error, but not an R error.