servr icon indicating copy to clipboard operation
servr copied to clipboard

View server logs?

Open stevecondylios opened this issue 5 years ago • 1 comments

Is there some way to view server logs?

E.g.

writeLines("<h1>Hi</H1>", "index.html")
servr::httd()

# createTcpServer: address already in use
# To stop the server, run servr::daemon_stop(2) or restart your R session
# Serving the directory /Users/st/R/localhost at http://127.0.0.1:7826

If we now visit http://127.0.0.1:7826 through the browser we see the html as expected.

But in the R console we don't see any details about that request (e.g. HTTP method, user agent, IP etc). Could it be possible to display it (perhaps optionally, with something along the lines of servr::httd(verbose = T)

stevecondylios avatar Jan 11 '20 04:01 stevecondylios

Most of the information is contained in the req object: https://github.com/yihui/servr/blob/3119445f7af10bec8255b8c8caeaef6da8ef7725/R/static.R#L164

Currently there is no way to show the information you mentioned. The main difficulty is I don't know what kind of information should be included in the logs. If I were to implement this at all, I'd probably provide a package option (e.g. options(servr.log = function(req) # whatever you want to do with req) so you can decide what to include in the log and extract the information from req.

yihui avatar Jan 12 '20 04:01 yihui