plumber2 has a build-in logging facility that takes care of logging any
conditions that are caught, as well as access logs. Further it is possible to
log custom messages using the log() method on the api object. However, the
actual logging is handled by a customizable function that can be set. You can
read more about the logging infrastructure in the
fiery documentation. plumber2 reexports the loggers
provided by fiery so they are immediately available to the user.
api_logger(api, logger = NULL, access_log_format = NULL)logger_null()
logger_console(format = "{time} - {event}: {message}")
logger_file(file, format = "{time} - {event}: {message}")
logger_logger(default_level = "INFO")
logger_otel(format = "{message}")
logger_switch(..., default = logger_null())
common_log_format
combined_log_format
A plumber2 api object to set the logger on
A logger function. If NULL then the current logger is kept
A glue string giving the format for the access logs.
plumber2 (through fiery) provides the predefined common_log_format and
combined_log_format, but you can easily create your own. See
fiery::loggers for which variables the glue string has access to.
A glue-like string specifying the format of the
log entry. Only the variables time, event, and message are available
and must be given verbatim
A file or connection to write to
The log level to use for events that are not request,
websocket, message, warning, or error
A named list of loggers to use for different events. The same
semantics as switch is used so it is possible to let events
fall through e.g. logger_switch(error =, warning = logger_file('errors.log')).
A catch-all logger for use with events not defined in ...
Logger setup doesn't have a dedicated annotation tag, but you can set it up
in a @plumber block
#* @plumber
function(api) {
api |>
api_logger(logger = logger_null())
}
# Use a different access log format
api() |>
api_logger(access_log_format = combined_log_format)
# Turn off logging
api() |>
api_logger(logger_null())
Run the code above in your browser using DataLab