脚本的日志记录名称-futile.logger R
我正在使用package脚本的日志记录名称-futile.logger R,r,logging,R,Logging,我正在使用packagefutile.logger将日志消息写入文件log.txt。 因为我的项目由6个脚本和20-22个函数组成,所以我希望有一条记录有脚本名称和函数名称的消息。 我创建了一个Logging函数,应该调用该函数来记录消息: Logging<-function(level,message) { #' Logs event to a Log/log.txt files #' #' @param level: String, Message level: inf
futile.logger
将日志消息写入文件log.txt
。
因为我的项目由6个脚本和20-22个函数组成,所以我希望有一条记录有脚本名称和函数名称的消息。
我创建了一个Logging
函数,应该调用该函数来记录消息:
Logging<-function(level,message)
{
#' Logs event to a Log/log.txt files
#'
#' @param level: String, Message level: info,error,debug (NO CAPS LOCK)
#' @param message: String, Message you want to Log
#'
#' @return write the file with the message specified by the user.
flog.appender(appender.file(file.path(getwd(),'Log/logs.txt')))
eval(parse(text=sprintf("flog.%s('%s')",level,message)))
}
其中记录了如下内容:
INFO [date hours] some log message
我想要一条消息,其中还包含调用日志记录
函数的脚本名称以及调用日志记录
函数的函数名称,即
INFO foo fun_1 [date hours] some log message
谢谢这有点晚了,但现在是徒劳的。logger提供了这样的功能 也就是说,你可以试试
fun_1 <- function() {
# doing some stuff
flog.info("some log message")}
fun\u 1对于将来的参考和读者,一种可能的解决方法是在要记录错误或成功执行的函数体内部调用match.call()[[1]]
,并粘贴到要传递给日志函数的消息字符串中。对此有何更新?我面临着类似的情况,我希望有任何解决办法
fun_1 <- function() {
# doing some stuff
flog.info("some log message")}
require(futile.logger)
# create output layout based on documentation and your needs
layout <- layout.format('[~l] [~f] [~t] ~m')
# set the created output
flog.layout(layout)
flog.threshold(DEBUG)
fun_1()
flog.appender(appender.file("log_example.log")))