使用RestServe将每个请求记录到单独的json文件中

使用RestServe将每个请求记录到单独的json文件中,r,restrserve,R,Restrserve,如何使用RestServe将每个请求记录到不同的json文件 我尝试使用like so中提到的lgr包: 但这会将请求的日志信息拆分为两个文件。我也很确定它对同时请求不起作用。我相信您甚至不需要任何特殊的记录器-只需使用writeLines即可。您还可以依赖req$id来命名文件,因为它是唯一的 library(RestRserve) req = Request$new() res = Response$new() fl = file.path(tempdir(), paste0(req$i

如何使用RestServe将每个请求记录到不同的json文件

我尝试使用like so中提到的lgr包:


但这会将请求的日志信息拆分为两个文件。我也很确定它对同时请求不起作用。

我相信您甚至不需要任何特殊的记录器-只需使用writeLines即可。您还可以依赖req$id来命名文件,因为它是唯一的

library(RestRserve)

req = Request$new()
res = Response$new()

fl = file.path(tempdir(), paste0(req$id, ".log"))
con = file(fl, open = "at")
writeLines("Process start", con)
res$set_body(sqrt(10))
writeLines("Process end", con)
close(con)

readLines(fl)
unlink(fl)
library(RestRserve)

req = Request$new()
res = Response$new()

fl = file.path(tempdir(), paste0(req$id, ".log"))
con = file(fl, open = "at")
writeLines("Process start", con)
res$set_body(sqrt(10))
writeLines("Process end", con)
close(con)

readLines(fl)
unlink(fl)