Title: | Logging Setup for the 'teal' Family of Packages |
Version: | 0.4.0 |
Date: | 2025-07-03 |
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. |
License: | Apache License 2.0 |
URL: | https://insightsengineering.github.io/teal.logger/, https://github.com/insightsengineering/teal.logger/ |
BugReports: | https://github.com/insightsengineering/teal.logger/issues |
Depends: | R (≥ 3.6) |
Imports: | glue (≥ 1.0.0), lifecycle (≥ 0.2.0), logger (≥ 0.4.0), methods, shiny (≥ 1.6.0), utils, withr (≥ 2.1.0) |
Suggests: | knitr (≥ 1.42), rmarkdown (≥ 2.27), testthat (≥ 3.2.3) |
VignetteBuilder: | knitr, rmarkdown |
RdMacros: | lifecycle |
Config/Needs/verdepcheck: | tidyverse/glue, r-lib/lifecycle, daroczig/logger, rstudio/shiny, r-lib/withr, yihui/knitr, rstudio/rmarkdown, r-lib/testthat |
Config/Needs/website: | insightsengineering/nesttemplate |
Encoding: | UTF-8 |
Language: | en-US |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-07-08 17:41:45 UTC; unardid |
Author: | Dawid Kaledkowski [aut, cre], Konrad Pagacz [aut], F. Hoffmann-La Roche AG [cph, fnd] |
Maintainer: | Dawid Kaledkowski <dawid.kaledkowski@roche.com> |
Repository: | CRAN |
Date/Publication: | 2025-07-08 18:10:02 UTC |
teal.logger: Logging Setup for the 'teal' Family of Packages
Description
Logging Setup for the teal
Family of Packages.
Author(s)
Maintainer: Dawid Kaledkowski dawid.kaledkowski@roche.com
Authors:
Konrad Pagacz
Other contributors:
F. Hoffmann-La Roche AG [copyright holder, funder]
See Also
Useful links:
Report bugs at https://github.com/insightsengineering/teal.logger/issues
Get value from environmental variable or R option or default in that order if the previous one is missing.
Description
Get value from environmental variable or R option or default in that order if the previous one is missing.
Usage
get_val(env_var_name, option_name, default = NULL)
Arguments
env_var_name |
( |
option_name |
( |
default |
optional, default value if both |
Value
an object of any class
Generate log layout function using common variables available via glue syntax including shiny session token
Description
Generate log layout function using common variables available via glue syntax including shiny session token
Usage
layout_teal_glue_generator(layout)
Arguments
layout |
( |
Details
this function behaves in the same way as logger::layout_glue_generator()
but allows the shiny session token (last 8 chars) to be included in the logging layout
Value
function taking level
and msg
arguments - keeping the original call creating the generator
in the generator attribute that is returned when calling log_layout for the currently used layout
Auto logging input changes in Shiny app
Description
This is to be called in the server
section of the Shiny app.
Usage
log_shiny_input_changes(
input,
namespace = NA_character_,
excluded_inputs = character(),
excluded_pattern = "_width$",
session = shiny::getDefaultReactiveDomain()
)
Arguments
input |
passed from Shiny |
namespace |
( |
excluded_inputs |
( |
excluded_pattern |
( |
session |
the Shiny session |
Details
Function having very similar behavior as logger::log_shiny_input_changes()
but adjusted for teal
needs.
Examples
## 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.
Description
Logs the basic information about the session.
Usage
log_system_info()
Value
invisible(NULL)
Register handlers for logging messages, warnings and errors
Description
Register handlers for logging messages, warnings and errors
Usage
register_handlers(namespace, package = namespace)
Arguments
namespace |
( |
package |
( |
Details
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.
Value
NULL
invisibly. Called for its side effects.
Note
Registering handlers is forbidden within tryCatch()
or withCallingHandlers()
.
Because of this, handlers are registered only if it is possible.
See Also
Examples
## Not run:
register_handlers("teal.logger")
# see the outcome
globalCallingHandlers()
## End(Not run)
Registers a logger instance in a given logging namespace.
Description
Usage
register_logger(namespace = NA_character_, layout = NULL, level = NULL)
Arguments
namespace |
( |
layout |
( |
level |
( |
Details
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
asTEAL.LOG_LAYOUT
, -
teal.log_level
asTEAL.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 tologger::layout_glue_generator()
, -
options(teal.log_level)
, which is passed tologger::log_threshold()
The logs are output to stdout
by default. Check logger
for more information
about layouts and how to use logger
.
Value
invisible(NULL)
Note
It's a thin wrapper around the logger
package.
See Also
The package vignettes for more help: browseVignettes("teal.logger")
.
Examples
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")
Suppress logger logs
Description
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.
Usage
suppress_logs()
Value
NULL
invisible
Examples
testthat::test_that("An example test", {
suppress_logs()
testthat::expect_true(TRUE)
})
Teal log_formatter
Description
Custom log_formatter
supporting atomic vectors. By default glue::glue
returns n-element vector when vector is provided as an input. This function
generates "[elem1, elem2, ...]"
for atomic vectors. Function also handles
NULL
value which normally causes logger
to return empty character.
Usage
teal_logger_formatter()
teal_logger_transformer(text, envir)
Arguments
text |
Text (typically) R code to parse and evaluate. |
envir |
environment to evaluate the code in |
Value
Nothing. Called for its side effects.