yihui / servr

A simple HTTP server in R
https://cran.rstudio.com/package=servr
278 stars 35 forks source link

View server logs? #40

Open stevecondylios opened 4 years ago

stevecondylios commented 4 years ago

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)

yihui commented 4 years ago

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.