> rsconnect::showLogs
function (appPath = getwd(), appFile = NULL, appName = NULL,
account = NULL, entries = 50, streaming = FALSE)
{
target <- deploymentTarget(appPath, appName, NULL, NULL,
account)
accountDetails <- accountInfo(target$account)
client <- lucidClient(shinyappsServerInfo()$url, accountDetails)
application <- getAppByName(client, accountDetails, target$appName)
if (is.null(application))
stop("No application found. Specify the application's directory, name, ",
"and/or associated account.")
if (streaming) {
httpType <- getOption("rsconnect.http", "rcurl")
if (!identical("rcurl", httpType)) {
stop("RCurl is required to show streaming logs. Install RCurl and set ",
"rsconnect.http to 'rcurl', or call showLogs with streaming = ",
"FALSE to show a log snapshot.")
}
}
if (streaming) {
rPath <- file.path(R.home("bin"), "R")
killfile <- tempfile()
outfile <- tempfile()
on.exit(unlink(outfile), add = TRUE)
cmd <- paste0("rsconnect:::showStreamingLogs(", "account = '",
target$account, "', ", "applicationId = '", application$id,
"', ", "entries = ", entries, ", ", "outfile = '",
gsub("\\", "\\\\", outfile, fixed = TRUE), "', ",
"killfile = '", gsub("\\", "\\\\", killfile, fixed = TRUE),
"')")
args <- paste("--vanilla", "--slave", paste0("-e \"",
cmd, "\""))
system2(command = rPath, args = args, stdout = NULL,
stderr = NULL, wait = FALSE)
tries <- 0
repeat {
tryCatch({
Sys.sleep(0.1)
tries <- tries + 1
logReader <- file(outfile, open = "rt", blocking = FALSE)
break
}, error = function(e, ...) {
if (tries > 500) {
stop("Failed to start log listener.")
}
}, warning = function(...) {
})
}
on.exit(close(logReader), add = TRUE)
repeat {
tryCatch({
if (file.exists(killfile))
break
writeLines(readLines(con = logReader, warn = FALSE))
Sys.sleep(0.1)
}, interrupt = function(...) {
close(file(killfile, open = "wt"))
}, error = function(e, ...) {
print(e$message)
})
}
}
else {
logs <- client$getLogs(application$id, entries, FALSE,
NULL)
cat(logs)
}
}
<environment: namespace:rsconnect>