log_call() hands each message to a logger. A logger is an S7 object that
inherits from logger_base, and logger_fn() decides how it is written.
Usage
logger_base(
trace = "TRACE",
debug = "DEBUG",
info = "INFO",
warn = "WARN",
error = "ERROR",
fatal = "FATAL",
threshold = "info",
logger = NULL
)
logger_fn(class, level, msg, ...)
logger_message(
trace = "TRACE",
debug = "DEBUG",
info = "INFO",
warn = "WARN",
error = "ERROR",
fatal = "FATAL",
threshold = "info",
logger = NULL
)Arguments
- trace, debug, info, warn, error, fatal
Labels passed to
logger_fn()for each level. They default to"TRACE","DEBUG"and so on. Change them when the logging package names its levels differently, or uses objects.- threshold
The lowest level the built-in loggers write: one of
"trace","debug","info","warn","error"or"fatal".- logger
An object a logging package needs to be passed, such as a log4r logger. Available to methods as
class@logger.- class
A logger. Methods are dispatched on this argument.
- level
The level label of the event, taken from the property of
classnamed by the event's level, e.g.class@info.- msg
The message, a string.
- ...
Passed to methods.
Details
logger_baseis the base class. The default method printsLEVEL [timestamp]: messageto the console.logger_messagewrites the sameLEVEL [timestamp]: messagewithmessage(), so it can be silenced withsuppressMessages().logger_fn(class, level, msg, ...)is the generic. Add a method to support any logging package, see extending_log.
logger_base and logger_message hide events below threshold. The trace
events, such as the calls leading to an error, are below the default
"info", so set threshold = "trace" to see them. A method for another
logging package is free to ignore threshold and use that package's own.
Examples
logger_message()
#> <fnware::logger_message>
#> @ trace : chr "TRACE"
#> @ debug : chr "DEBUG"
#> @ info : chr "INFO"
#> @ warn : chr "WARN"
#> @ error : chr "ERROR"
#> @ fatal : chr "FATAL"
#> @ threshold: chr "info"
#> @ logger : NULL
f := log_call(logger = logger_message()) %@% function(x) x
f(1)
#> INFO [2026-11-11T17:04:40.596Z]: Start f(x=1)
#> INFO [2026-11-11T17:04:40.596Z]: Finished f(x=1) Elapsed=00:00:00.000
#> [1] 1
