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).