Log stdout + stderr and stderr simultaneously in R

半城伤御伤魂 提交于 2020-04-16 05:49:33

问题


I want to have all stdout + stderr in one log file and simultaneously just stderr in another. How can I achieve this in R? Messages must keep the chronological order of all messages in both logs, for example say I have this code:

options(warn = 1)
cat("1st stdout\n")
warning("2nd stderr")
cat("3rd stdout\n")
warning("4th stderr")

How to make it redirect to both logs in the desired way?

My thought that it could be simple if it was possible to merge and split the R connections, see the question here: How to merge and split R connections?

I am not against special logging frameworks, but it is preferable to be able to log from functions like cat, warning, message, stop etc. without changing the code to different functions (since I also use different packages).

来源:https://stackoverflow.com/questions/60925357/log-stdout-stderr-and-stderr-simultaneously-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!