Add a log entry
log_add.Rd
Adds a structured entry to a named log, capturing metadata such as timestamp, calling function, event type, message, arguments used, optional output, and more.
Usage
log_add(
event,
message,
name = getOption("pipfun.log.default"),
args = NULL,
logmeta = NULL,
output = NULL,
.trace = NULL,
.env = rlang::caller_env()
)
Arguments
- event
Type of event (e.g.
"error"
,"info"
,"warning"
).- message
Description of the log entry.
- name
Name of the log (default:
options("pipfun.log.default")
).- args
Optional list of captured arguments (default: auto-captured).
- logmeta
Optional named list of metadata to attach (merged with args).
- output
Optional result or return value.
- .trace
Optional call stack or trace override.
- .env
Internal use. Calling environment (default:
rlang::caller_env()
).
Details
This function automatically captures all arguments from the calling function,
including ...
. You can also manually add custom metadata using the
logmeta
argument.
Examples
log_init("demo_log", overwrite = TRUE)
# Automatically captures arguments from the caller:
my_fun <- function(x, y = 1, ...) {
result <- x + y
log_info("Ran my_fun", name = "demo_log", output = result)
return(result)
}
my_fun(3, z = 9)
#> [1] 4
# Add custom metadata manually:
log_info("Logging manually", name = "demo_log",
logmeta = list(stage = "processing", user = "analyst"))