我目前正在使用 restrserve 创建一个 REST API。在尝试向我的应用程序添加记录器时,我遇到了这个问题。通过将日志级别设置为:application$logger$set_log_level("error"),我的控制台输出错误具有如下 JSON 结构:
{
"timestamp":"2020-09-22 18:25:37.425642",
"level":"ERROR",
"name":"Application",
"pid":38662,
"msg":"",
"context":{
"request_id":"alphanumeric string",
"message":{ here is the description of the error }
}
}
我按照网站上的说明设置了打印机功能,但是在可用字段(时间戳、级别、logger_name、pid、消息)中,“上下文”不存在,所以基本上,通过打印消息,我的日志是空文件. 这是我的打印机功能:
application$logger$set_printer(FUN = function(timestamp, level, logger_name, pid, message, ...){
write(message, file = paste("/Log/Monitor_", pid,
timestamp, ".txt", sep = ""))
# attempting to print "context" raises an error!
})
有没有办法将控制台输出中存在的“上下文”字段打印到文件中?
在此先感谢,任何建议都会非常有帮助