Learn R Programming

redcapAPI (version 2.11.4)

logEvent: Log event

Description

This is one of the more complex integration of services into the `redcapAPI`` package. It's purpose is to provide the ability for a system administrator (or user) to integrate logging into a report or application. The ability to inject a logging framework without a developer's code being altered.

Usage

logEvent(severity, ...)

createSplunkFUN( token = Sys.getenv("SPLUNK_TOKEN"), url = Sys.getenv("SPLUNK_URL"), project = Sys.getenv("SPLUNK_PROJECT"), allowDebug = FALSE )

logWarning(...)

logStop(...)

logMessage(...)

Arguments

severity

string One of the following: 'TRACE', 'DEBUG', 'INFO', 'WARN', or 'ERROR'

...

Information to include in the log event. Each argument must have a name.

token

string The API_KEY for calling logger.

url

string The url of the logging server

project

string The project name to appear in the logs

allowDebug

logical(1) Should debug mode be allowed when using the default SPLUNK function. Defaults to FALSE.

Details

To do this the callback function is pulled from the option redcapAPI_logger which defaults to doing nothing.

When the package starts up, it checks to see if SPLUNK_TOKEN and SPLUNK_URL ENV variables are set and if so, it automatically redirects the redcapAPI_logger to point at Splunk. It will also use SPLUNK_PROJECT if defined, otherwise the project will be the directory name that the code is executing from.

There are also two helper functions logWarning and logStop which will call logging if enabled first, then warn or stop as requested.

The function createSplunkFUN will create a SPLUNK logger callback function. It will pull 'SPLUNK_TOKEN', 'SPLUNK_URL' and 'SPLUNK_PROJECT' from ENV if the corresponding arguments are not specified.

Examples

Run this code
if (FALSE) {
  options(redcapAPI_logger=function(severity, ...) {cat(severity, ' ', dput(list(...)), '\n')})
  logEvent("INFO", "This is a logged event")
}

Run the code above in your browser using DataLab