| Title: | Logging Setup for the 'teal' Family of Packages |
|---|---|
| Description: | Utilizing the 'logger' framework to record events within a package, specific to 'teal' family of packages. Supports logging namespaces, hierarchical logging, various log destinations, vectorization, and more. |
| Authors: | Dawid Kaledkowski [aut, cre], Konrad Pagacz [aut], F. Hoffmann-La Roche AG [cph, fnd] |
| Maintainer: | Dawid Kaledkowski <[email protected]> |
| License: | Apache License 2.0 |
| Version: | 0.4.1 |
| Built: | 2026-05-31 06:11:21 UTC |
| Source: | https://github.com/insightsengineering/teal.logger |
This is to be called in the server section of the Shiny app.
log_shiny_input_changes( input, namespace = NA_character_, excluded_inputs = character(), excluded_pattern = "_width$", session = shiny::getDefaultReactiveDomain() )log_shiny_input_changes( input, namespace = NA_character_, excluded_inputs = character(), excluded_pattern = "_width$", session = shiny::getDefaultReactiveDomain() )
input |
passed from Shiny |
namespace |
( |
excluded_inputs |
( |
excluded_pattern |
( |
session |
the Shiny session |
Function having very similar behavior as logger::log_shiny_input_changes() but adjusted for teal needs.
## Not run: library(shiny) ui <- bootstrapPage( numericInput("mean1", "mean1", 0), numericInput("mean2", "mean2", 0), numericInput("sd", "sd", 1), textInput("title", "title", "title"), textInput("foo", "This is not used at all, still gets logged", "foo"), passwordInput("password", "Password not to be logged", "secret"), plotOutput("plot") ) server <- function(input, output) { log_shiny_input_changes(input, excluded_inputs = "password", excluded_pattern = "mean") output$plot <- renderPlot({ hist(rnorm(1e3, input$mean1, input$sd), main = input$title) }) } shinyApp(ui = ui, server = server) ## End(Not run)## Not run: library(shiny) ui <- bootstrapPage( numericInput("mean1", "mean1", 0), numericInput("mean2", "mean2", 0), numericInput("sd", "sd", 1), textInput("title", "title", "title"), textInput("foo", "This is not used at all, still gets logged", "foo"), passwordInput("password", "Password not to be logged", "secret"), plotOutput("plot") ) server <- function(input, output) { log_shiny_input_changes(input, excluded_inputs = "password", excluded_pattern = "mean") output$plot <- renderPlot({ hist(rnorm(1e3, input$mean1, input$sd), main = input$title) }) } shinyApp(ui = ui, server = server) ## End(Not run)
Logs the basic information about the session.
log_system_info()log_system_info()
invisible(NULL)
Register handlers for logging messages, warnings and errors
register_handlers(namespace, package = namespace)register_handlers(namespace, package = namespace)
namespace |
( |
package |
( |
This function registers global handlers for messages, warnings and errors. The handlers will investigate the call stack and if it contains a function from the package, the message, warning or error will be logged into the respective namespace.
The handlers are registered only once per package and type. Consecutive calls will no effect.
Registering handlers for package base is not supported.
Use TEAL.LOG_MUFFLE environmental variable or teal.log_muffle R option to optionally
control recover strategies. If TRUE (a default value) then the handler will jump to muffle
restart for a given type of condition and doesn't continue (with output to the console).
Applicable for message and warning types only. The errors won't be suppressed.
NULL invisibly. Called for its side effects.
Registering handlers is forbidden within tryCatch() or withCallingHandlers().
Because of this, handlers are registered only if it is possible.
## Not run: register_handlers("teal.logger") # see the outcome globalCallingHandlers() ## End(Not run)## Not run: register_handlers("teal.logger") # see the outcome globalCallingHandlers() ## End(Not run)
Registers logger instance.
register_logger(namespace = NA_character_, layout = NULL, level = NULL)register_logger(namespace = NA_character_, layout = NULL, level = NULL)
namespace |
( |
layout |
( |
level |
( |
Creates a new logging namespace specified by the namespace argument.
When the layout and level arguments are set to NULL (default), the function
gets the values for them from system variables or R options.
When deciding what to use (either argument, an R option or system variable), the function
picks the first non NULL value, checking in order:
Function argument.
System variable.
R option.
layout and level can be set as system environment variables, respectively:
teal.log_layout as TEAL.LOG_LAYOUT,
teal.log_level as TEAL.LOG_LEVEL.
If neither the argument nor the environment variable is set the function uses the following R options:
options(teal.log_layout), which is passed to logger::layout_glue_generator(),
options(teal.log_level), which is passed to logger::log_threshold()
The logs are output to stdout by default. Check logger for more information
about layouts and how to use logger.
invisible(NULL)
It's a thin wrapper around the logger package.
The package vignettes for more help: browseVignettes("teal.logger").
options(teal.log_layout = "{msg}") options(teal.log_level = "ERROR") register_logger(namespace = "new_namespace") logger::log_info("Hello from new_namespace", namespace = "new_namespace")options(teal.log_layout = "{msg}") options(teal.log_level = "ERROR") register_logger(namespace = "new_namespace") logger::log_info("Hello from new_namespace", namespace = "new_namespace")
This function suppresses logger when running tests via testthat.
To suppress logs for a single test, add this function
call within the testthat::test_that expression. To suppress logs for an entire
test file, call this function at the start of the file.
suppress_logs()suppress_logs()
NULL invisible
testthat::test_that("An example test", { suppress_logs() testthat::expect_true(TRUE) })testthat::test_that("An example test", { suppress_logs() testthat::expect_true(TRUE) })