To be used for logging at application level (i.e. when a shiny session is started) or at report level (i.e. each time a report is run). Logging of single report events should be made from reactive enviroments within the shiny server function or from within the (report) functions used by the same reactive environments.

appLogger(session, msg = "No message provided")

repLogger(session, msg = "No message provided",
  .topcall = sys.call(-1), .topenv = parent.frame())

subLogger(author, registryName, reshId, msg = "No message provided",
  .topcall = sys.call(-1), .topenv = parent.frame())

Arguments

session

Shiny session object to be used for getting user data. For testing and development purposes session can be replaced by list() in which case various config options might be used to provide something sensible

msg

String providing a user defined message to be added to the log record. Default value is 'No message provided'

.topcall

Parent call (if any) calling this function. Used to provide the function call with arguments. Default value is sys.call(-1)

.topenv

Name of the parent environment calling this function. Used to provide package name (i.e. register) this function was called from. Default value is parent.frame()

author

String providing author of a report. Only used for automated subscription reports that are run outside a shiny session.

registryName

String providing registry name. Only used for automated subscription reports that are run outside a shiny session.

reshId

String providing the organization id of the (subscription) report author. Only used for automated subscription reports that are run outside a shiny session.

Value

Returns nothing but calls a logging appender

Details

The below fields will be appended to the log, in the following order:

  1. time: date-time as event is logged as format(time, "%Y-%m-%d %H:%M:%S")

  2. user: username as found in the shiny session object

  3. name: full name of user as found in the shiny session object

  4. group: users group membership as provided by the shiny session object. Normally, this will correspond to the registry the user belongs to

  5. role: users role as provided by the shiny session object. Its value will depend on whatever is delivered by the autorization provider, but for OpenQReg registires 'LU' (local user) and 'SC' (system coordinator) are typical values

  6. resh_id: the organization id of the current user as provided by the shiny session object

  7. environment: environment from where the logger function was called (only provided by repLogger())

  8. call: function (with arguments) from where the logger was called (only provided by repLogger())

  9. message: an optional message defined as argument to the function

Note

Pseudo code of how appLogger() may be implemented:

library(shiny)
library(raplog)

server <- function(input, output, session) {
  raplog::appLogger(session, msg = "Smerteregisteret: starting shiny app")
  ...
}

Pseudo code on how repLogger() can be implemented as part of a function in a reactive (shiny) context. First, this is an example of the shiny server function with the (reactive) function renderPlot() calling a function that provides a histogram:

library(shiny)
library(raplog)

server <- function(input, output, session) {
  ...
  output$hist <- renderPlot({
    makeHist(data, var = input$var, bins = input$bins, session = session)
  })
  ...
}

Then, logging is called within the function makeHist():

makeHist <- function(data, var, bins, ...) {

  if ("session" %in% names(list(...))) {
    raplog::repLogger(session = list(...)[["session"]], msg = "Providing histogram")
  }
  ...
}

Examples

# \donttest{ # Depend on the environment variable R_RAP_CONFIG_PATH being set appLogger(list())
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> Error in appendLog(event, name, target = "file", format = "csv"): There is nowhere to append the logging event. The environment variable R_RAP_CONFIG_PATH should be defined!
# } # \donttest{ # Depend on the environment variable R_RAP_CONFIG_PATH being set repLogger(list())
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> System has no defined instance. Configuration as provided by #> 'rapbaseConfig.yml' will be used as source for user data.
#> Error in appendLog(event, name, target = "file", format = "csv"): There is nowhere to append the logging event. The environment variable R_RAP_CONFIG_PATH should be defined!
# } # \donttest{ # Depend on the environment variable R_RAP_CONFIG_PATH being set subLogger(author = "Rapporteket", registryName = "rapbase", reshId = "999999")
#> Error in appendLog(event, name, target = "file", format = "csv"): There is nowhere to append the logging event. The environment variable R_RAP_CONFIG_PATH should be defined!
# }