-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Funksjon for å aktivere logging i json-format
La det inn i fila appLog.R. Det som lå der var en definisjon noe data i pakken. Denne definisjonen flyttet jeg til data.R
- Loading branch information
Showing
10 changed files
with
122 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,39 @@ | ||
#' App log test dataset. | ||
#' | ||
#' A dataset containing test entries for the application log. | ||
#' | ||
#' @format A data frame with 20 rows and 7 variables: | ||
#' \describe{ | ||
#' \item{time}{character timestamp} | ||
#' \item{user}{user name} | ||
#' \item{name}{user full name} | ||
#' \item{group}{users group/registry} | ||
#' \item{role}{users role} | ||
#' \item{resh_id}{users organization} | ||
#' \item{message}{log message} | ||
#' } | ||
"appLog" | ||
#' Settings for logging as json | ||
#' | ||
#' Every info, warning and error will be logged in json format. | ||
#' | ||
#' @param usernameEnv Global variable containing user name | ||
#' @param appidEnv Global variable containing application name | ||
#' @param testing Is the if function running in a test? | ||
#' Function will skip some calls if it does. | ||
#' | ||
#' @export | ||
#' | ||
loggerSetup <- function( | ||
usernameEnv = "SHINYPROXY_USERNAME", | ||
appidEnv = "SHINYPROXY_APPID", | ||
testing = FALSE | ||
) { | ||
logger::log_threshold(logger::INFO) | ||
formatterJson <- function(level, message, ...) { | ||
username <- Sys.getenv(usernameEnv, unset = "unknown") | ||
appid <- Sys.getenv(appidEnv, unset = "unknown") | ||
return(jsonlite::toJSON( | ||
list( | ||
time = format(Sys.time(), "%Y-%m-%d %H:%M:%OS3"), | ||
level = attr(level, "level"), | ||
app = appid, | ||
user = username, | ||
message = message | ||
), | ||
auto_unbox = TRUE | ||
) | ||
) | ||
} | ||
logger::log_layout(formatterJson) | ||
if (!testing) { | ||
logger::log_messages() | ||
logger::log_warnings() | ||
logger::log_errors() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#' App log test dataset. | ||
#' | ||
#' A dataset containing test entries for the application log. | ||
#' | ||
#' @format A data frame with 20 rows and 7 variables: | ||
#' \describe{ | ||
#' \item{time}{character timestamp} | ||
#' \item{user}{user name} | ||
#' \item{name}{user full name} | ||
#' \item{group}{users group/registry} | ||
#' \item{role}{users role} | ||
#' \item{resh_id}{users organization} | ||
#' \item{message}{log message} | ||
#' } | ||
"appLog" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ reference: | |
desc: > | ||
Handle logging | ||
contents: | ||
- loggerSetup | ||
- logger | ||
- sanitizeLog | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.