#' parse_logs
#'
#' @param logs_vec a character vector of JSON formatted log messages
#'
#' @return a data frame of parsed log messages
#'
#' @export
#'
#' @importFrom jsonlite fromJSON
#' @importFrom dplyr bind_rows select %>%
#' @importFrom rlang .data
#'
parse_logs <- function(logs_vec) {
dat <- lapply(logs_vec, function(log_msg) {
out <- NULL
tryCatch({
out <- jsonlite::fromJSON(log_msg)
}, error = function(err) {
print(err)
# if JSON parsing fails then we will keep the original log message
out <<- list(
"timestamp" = time_now_utc(),
"request_method" = NA,
"path_info" = NA,
"account_uid" = NA,
"user_uid" = NA,
"app_uid" = NA,
"type" = NA,
"page" = NA,
"message" = log_msg
)
})
out <- lapply(out, function(col_value) {
if (length(col_value) == 0) {
return(NA)
} else {
return(col_value)
}
})
out
})
dplyr::bind_rows(dat) %>%
# reorder columns
dplyr::select(
.data$timestamp,
.data$request_method,
.data$path_info,
.data$account_uid,
.data$user_uid,
.data$app_uid,
.data$type,
.data$page,
.data$message
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.