R Logging display name of the script

Wednesday, July 2, 2014

this is an atomic example of my current issue:

For the moment I have a project containing several R scripts (all in the same directory named DIR). I have a main script in DIR sourcing all the R files and, containing a basicconfig:


I take two scripts in DIR, dog.r and cat.r. I have currently only one function in these scripts. In dog.r :

feedDog <- function(){
loginfo("The dog is happy to eat!", logger="dog.r")


And in cat.r :

feedCat <- function(){
loginfo("The cat is voracious", logger="cat.r")

It's fine with this example. But in real I have something like 20 scripts and 20 possible error messages in each. So that instead of writting:

loginfo("some message", logger="name of script")

I would like to write:

loginfo("some message", logger=logger)

And configure different loggers. The issue is that if I declare a logger in each R scripts, only one will be taken into account when I source all files with my main ... I dunno how to bypass this issue.

PS: in Python it is possible to define a logger in each file taking automatically the name of the script like this:

logger = logging.getLogger(__name__)

But I am afraid it is not possible in R ?