如何混合flog.fatal并停止

时间:2015-07-06 21:51:16

标签: r logging error-handling

我开始使用futile.logger包。有一个很好的FATAL错误记录,我希望与stop结合使用。 但是我说:

stop(flog.fatal('crash for some reason'))

我得到了

[FATAL] [2015-07-06 22:46:54] [base.stop] crash for some reason

Error: 
[FATAL] [2015-07-06 22:46:54] [base.stop] crash for some reason

在记录stop记录的内容

之后,我怎样才能flog.fatal(中止程序)

所以[FATAL] [2015-07-06 22:46:54] [base.stop] crash for some reason就是这样

2 个答案:

答案 0 :(得分:0)

你提出的问题似乎微不足道?只是做

flog.fatal('crash for some reason'); stop()

(我个人认为futile.logger对于将文本消息写入文件而不是控制台更有用,但也可以使用R的条件message(), warning(), stop()等将消息打印到控制台。

flog.fatal返回的值是一个停止打印的字符向量(长度为1)。

res <- flog.fatal('crash for some reason')
print(res)

答案 1 :(得分:0)

作为替代方案,您可以使用ftry包中的futile.logger函数。

> futile.logger::ftry(log("a"))
ERROR [2017-08-22 10:50:51] non-numeric argument to mathematical function
Error in log("a") : non-numeric argument to mathematical function