daroczig / logger

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

make sure there are no unknown named arguments fix #140 #141

Closed daroczig closed 7 months ago

daroczig commented 7 months ago

After taking a look at the test results, and thinking this through more, I think failing on named args is not a viable solution, as there are many valid cases to pass named args, e.g. when using JSON loggers, or the below dummy example:

log_info('Hello, {v}!', v = 'world')
INFO [2024-02-29 00:26:30] Hello, world!
MichaelChirico commented 7 months ago

hmm, in that case, maybe it's the description of '...' that's misleading?

https://github.com/daroczig/logger/blob/ec619ce09d4db7c428745f8152a05907b92cdae9/R/logger.R#L214

daroczig commented 7 months ago

I'm not sure if that's misleading, but suggestions welcomed. Formatters take the args and convert to string. Some formatters support named args .. but those are still R objects. If it's confusing, pls suggest better language 🙏

MichaelChirico commented 7 months ago

My initial read is that something like do.call(paste, within(lapply(list(...), as.character), sep = "") would be done. Indeed that appears the case for un-named entries to .... But named arguments are handled differently -- they're used as an environment for substituting values into the unnamed parts of ... (much like glue()). So this distinction of named/unnamed parts of ... is totally absent.

This is an instructive example I think:

log_info('{a}', '{a}{b}', '{a}{b}{c}', a=1, b=2, c=3)
# INFO [2024-02-28 16:21:37] 112123