daroczig / logger

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

skip_formater does not work for the second argument #84

Closed vspinu closed 6 months ago

vspinu commented 3 years ago

This works:

> log_error(skip_formatter("{\"x\": [\"a\"]}"))
ERROR [2021-05-07 16:40:14] {"x": ["a"]}

This does not work:

> log_error("xxx:", skip_formatter("{\"x\": [\"a\"]}"))
Error in value[[3L]](cond) : `glue` failed in `formatter_glue` on:

  chr "xxx:" 

Raw error message:

 <text>:1:6: unexpected '['
1: "x": [
         ^ 

Please consider using another `log_formatter` or `skip_formatter` on strings with curly braces.
daroczig commented 3 years ago

Hm, probably this is a documentation problem, but a formatter fn runs on ... as-is, and not separately for each element of .... In other words, the default formatter_glue will take all ... params, so glue will fail.

The skip_formatter approach only works if that's the only (string) object passed, like in your first example.

Not sure who to try to explain this better .. does it make sense?

vspinu commented 3 years ago

I see, so ... are just passed to formatter as is then?

Then I would expect this to work

> log_error(skip_formatter("xxx:"), "{\"x\": [\"a\"]}")
ERROR [2021-05-08 11:24:38] xxx:

skip_formater should mean that the default, plain formatter (paste?) is run on the entire thing including ....

vspinu commented 3 years ago

the formater_glue_or_sprintf suits my needs really well actually. So I think this issue can be treated as a documentation issue indeed.