[back to the tutorial]  

integration with R

thanks Henrico Witvliet for this hint

you can instruct R to send its text to a logger using the function withCallingHandlers. combine this with options(warn=-1) and you have replaced the R built in warning logic with the logging package.

imagine you want all warnings in function F go to logger L, you use this construction:

    warning=function(w) { logwarn(w, logger=L) })

try it with, for example, log(-1).

> withCallingHandlers(log(-1), warning = function(w){logwarn(w, logger='mylogger')})
2010-11-03 09:24:04 WARNING:mylogger:simpleWarning in log(-1): NaNs produced