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())
session | Shiny session object to be used for getting user data.
For testing and development purposes |
---|---|
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 |
.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 |
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. |
Returns nothing but calls a logging appender
The below fields will be appended to the log, in the following order:
time
: date-time as event is logged as
format(time, "%Y-%m-%d %H:%M:%S")
user
: username as found in the shiny session object
name
: full name of user as found in the shiny session object
group
: users group membership as provided by the shiny
session object. Normally, this will correspond to the registry the user
belongs to
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
resh_id
: the organization id of the current user as provided
by the shiny session object
environment
: environment from where the logger function was
called (only provided by repLogger()
)
call
: function (with arguments) from where the logger was
called (only provided by repLogger()
)
message: an optional message defined as argument to the function
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") } ... }
#>#>#>#>#>#>#>#>#>#>#> 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!#>#>#>#>#>#>#>#>#>#>#> 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!# }