Title: | Record Events and Issues |
---|---|
Description: | Logger to keep track of informational events and errors useful for debugging. |
Authors: | John Coene [aut, cre], Opifex [cph] |
Maintainer: | John Coene <[email protected]> |
License: | AGPL-3 |
Version: | 1.1.1 |
Built: | 2025-03-14 07:37:43 UTC |
Source: | CRAN |
Default logger used to log inputs in logApp()
.
inputLogger
inputLogger
An object of class Logger
(inherits from R6
) of length 13.
Log Check
is.log(obj)
is.log(obj)
obj |
Object to check. |
TRUE
if object is a logger,
and FALSE
otherwise.
info <- Logger$new("INFO") is.log(info)
info <- Logger$new("INFO") is.log(info)
Create a logger.
printer
A callback function to write the message
to the console, must accept a single argument,
defaults to cat
.
predicate
A predicate function that determines whether to actually run the log, useful if you want to switch the logger on and off for debugging.
If the function returns TRUE
the logger runs as normal,
if FALSE
the logger does not actually print, write or
dump the messages.
new()
Logger$new(prefix = NULL, write = FALSE, file = "log.log", sep = "\t")
prefix
String to prefix all log messages.
write
Whether to write the log to the file
.
file
Name of the file to dump the logs to,
only used if write
is TRUE
.
sep
Separator between prefix
and other flags
and messages.
Initialise
info <- Logger$new("INFO") info$log("hello")
date()
Logger$date(format = "%d-%m-%Y")
format
Formatter for the item, passed
to format()
.
Include the date in the log
info <- Logger$new("INFO")$date() info$log("today")
time()
Logger$time(format = "%H:%M:%S")
format
Formatter for the item, passed
to format()
.
Include the time in the log
info <- Logger$new("INFO")$time() info$log("now")
unix()
Logger$unix()
Include the time in the log
info <- Logger$new("INFO")$unix() info$log("timestamp")
hook()
Logger$hook(fn)
fn
A function that accepts one argument (string) and returns a modified version of that string.
Preprocess the prefix with a custom function
err <- Logger$new("INFO")$hook(crayon::red) err$log("hello")
dir()
Logger$dir()
Include the directory in the log
info <- Logger$new("INFO")$dir() info$log("directory")
flag()
Logger$flag(what)
what
Function to run for every message logged or string to include in log message.
Pass a custom flag
fl <- function(){ paste0(sample(letters, 4), collapse = "") } info <- Logger$new("INFO")$flag(fl) info$log("random")
log()
Logger$log(..., sep = " ", collapse = " ")
...
Elements to compose message.
sep, collapse
Separators passed to paste()
.
Log messages
info <- Logger$new("INFO") info$log("Logger")
dump()
Logger$dump(file = "dump.log")
file
Name of the file to dump the logs to.
Dump the log to a file
info <- Logger$new("INFO") info$log("hello") \dontrun{info$dump()}
clone()
The objects of this class are cloneable with this method.
Logger$clone(deep = FALSE)
deep
Whether to make a deep clone.
info <- Logger$new("INFO")$ date()$ time()$ hook(crayon::blue) info$log("Hello") Sys.sleep(.7) info$log("World") ## ------------------------------------------------ ## Method `Logger$new` ## ------------------------------------------------ info <- Logger$new("INFO") info$log("hello") ## ------------------------------------------------ ## Method `Logger$date` ## ------------------------------------------------ info <- Logger$new("INFO")$date() info$log("today") ## ------------------------------------------------ ## Method `Logger$time` ## ------------------------------------------------ info <- Logger$new("INFO")$time() info$log("now") ## ------------------------------------------------ ## Method `Logger$unix` ## ------------------------------------------------ info <- Logger$new("INFO")$unix() info$log("timestamp") ## ------------------------------------------------ ## Method `Logger$hook` ## ------------------------------------------------ err <- Logger$new("INFO")$hook(crayon::red) err$log("hello") ## ------------------------------------------------ ## Method `Logger$dir` ## ------------------------------------------------ info <- Logger$new("INFO")$dir() info$log("directory") ## ------------------------------------------------ ## Method `Logger$flag` ## ------------------------------------------------ fl <- function(){ paste0(sample(letters, 4), collapse = "") } info <- Logger$new("INFO")$flag(fl) info$log("random") ## ------------------------------------------------ ## Method `Logger$log` ## ------------------------------------------------ info <- Logger$new("INFO") info$log("Logger") ## ------------------------------------------------ ## Method `Logger$dump` ## ------------------------------------------------ info <- Logger$new("INFO") info$log("hello") ## Not run: info$dump()
info <- Logger$new("INFO")$ date()$ time()$ hook(crayon::blue) info$log("Hello") Sys.sleep(.7) info$log("World") ## ------------------------------------------------ ## Method `Logger$new` ## ------------------------------------------------ info <- Logger$new("INFO") info$log("hello") ## ------------------------------------------------ ## Method `Logger$date` ## ------------------------------------------------ info <- Logger$new("INFO")$date() info$log("today") ## ------------------------------------------------ ## Method `Logger$time` ## ------------------------------------------------ info <- Logger$new("INFO")$time() info$log("now") ## ------------------------------------------------ ## Method `Logger$unix` ## ------------------------------------------------ info <- Logger$new("INFO")$unix() info$log("timestamp") ## ------------------------------------------------ ## Method `Logger$hook` ## ------------------------------------------------ err <- Logger$new("INFO")$hook(crayon::red) err$log("hello") ## ------------------------------------------------ ## Method `Logger$dir` ## ------------------------------------------------ info <- Logger$new("INFO")$dir() info$log("directory") ## ------------------------------------------------ ## Method `Logger$flag` ## ------------------------------------------------ fl <- function(){ paste0(sample(letters, 4), collapse = "") } info <- Logger$new("INFO")$flag(fl) info$log("random") ## ------------------------------------------------ ## Method `Logger$log` ## ------------------------------------------------ info <- Logger$new("INFO") info$log("Logger") ## ------------------------------------------------ ## Method `Logger$dump` ## ------------------------------------------------ info <- Logger$new("INFO") info$log("hello") ## Not run: info$dump()
Serve a plumber API with metrics, use this function
like you would use plumber::pr()
.
prLog(file = NULL, ..., requests = requestLogger) prWithLog(pr, requests = requestLogger)
prLog(file = NULL, ..., requests = requestLogger) prWithLog(pr, requests = requestLogger)
file |
Plumber file as passed to |
... |
Any other argument to pass to |
requests |
Logger to log requests, set to |
pr |
Plumber API as returned by |
Serve a shiny application with default loggers, useful for debugging.
logApp(ui, server, ..., inputs = inputLogger) shinyWithLog(app, inputs = inputLogger)
logApp(ui, server, ..., inputs = inputLogger) shinyWithLog(app, inputs = inputLogger)
ui , server
|
UI definition and server function
as passed to |
... |
Any other arguments passed to |
inputs |
Logger to log inputs, set to |
app |
Shiny application as returned by |
Template loggers for convenience.
infoLog(prefix = "INFO") errorLog(prefix = "ERROR") warningLog(prefix = "WARNING") successLog(prefix = "SUCCESS")
infoLog(prefix = "INFO") errorLog(prefix = "ERROR") warningLog(prefix = "WARNING") successLog(prefix = "SUCCESS")
prefix |
The prefix to use, this is passed to Logger. |
info <- infoLog() info$log("Information")
info <- infoLog() info$log("Information")