daroczig / logger

A lightweight, modern and flexible, log4j and futile.logger inspired logging utility for R
https://daroczig.github.io/logger
249 stars 38 forks source link

Formatter placeholder `{fn}` sometimes prints function body not function name from within `do.call` #114

Closed PuzzledFace closed 4 months ago

PuzzledFace commented 1 year ago

#20 appears related.

When called within do.call, the {fn} placeholder prints the body of the the called function, not its name. Here is a MRE.

> log_layout(layout_glue_generator(format = '{fn}: {msg}'))
> myFunc <- function() {
+   log_info("Hello")
+ }
> myFunc()
myFunc: Hello

But

> do.call(myFunc, list())
function () { log_info("Hello") }: Hello

However

> do.call("myFunc", list())
myFunc: Hello

Consistent behaviour would be good, behaviour as per "function name as character string" would be ideal!

daroczig commented 4 months ago

When running do.call(myFunc, list()), the myFunc function name will not be known to logger because myFunc is evaluated first, and only its "value" (the actual fn) is being called by do.call and so thus tracked by logger.

I don't think this can be solved within the logger world.