daroczig / logger

A lightweight, modern and flexible, log4j and futile.logger inspired logging utility for R
https://daroczig.github.io/logger
249 stars 38 forks source link

New arguments for `log_shiny_input_changes` #154

Closed m7pr closed 2 months ago

m7pr commented 2 months ago

This PR introduces 3 new parameters

#' @param allow allow to be used outside Shiny app
#' @param change_message custom message to be displayed during the input change - supports `glue` syntax where `{name}`
#' is the name of the input, and `{old}` and `{new}` are input values before the change and after the change
#' @param initialize_message custom message to be displayed during input initialization (this is followed by initialized
#' input values being printed in JSON format)

@param allow

allow is needed to skip the stop() statement that blocks the usage of log_shiny_input_changes outside of Shiny app. However there are use cases where the usage outside Shiny app make sense, e.g. in Shiny Tests:

library(shiny)
server <- function(input, output, session) {
  logger::log_shiny_input_changes()
  x <- reactive(input$a * input$b)
}

testServer(server, {
  session$setInputs(a = 2, b = 3)
  stopifnot(x() == 6)
})
Error in logger::log_shiny_input_changes() :
No Shiny app running, it makes no sense to call this function outside of a Shiny app

@param *_message

If there is multiple server modules that utilize log_shiny_input_changes with similar input names, it would be beneficial to be able to append the log_shiny_input_changes messages with user-defined messages (e.g. such messages that include name of the function in the message). So I proposed to have messages used in this function as parameters that a user can overwrite.

m7pr commented 2 months ago

@daroczig or we could extend existing messages so they display namespace

ns <- session$ns("")
log_level(level, "Shiny input change detected in {ns} on {name}: {old} -> {new}", namespace = namespace)
m7pr commented 2 months ago

clsoing this in favour of https://github.com/daroczig/logger/pull/155