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

logger cannot be used in `reprex::reprex()` #127

Closed DanChaltiel closed 11 months ago

DanChaltiel commented 11 months ago

Hi,

It seems that logger cannot be used in reprex::reprex().

For example, here is a manual reprex from copypasting my console :

logger::log_warn("foobar")
# WARN [2023-10-22 16:52:16] foobar

Created on 2023-10-22 with my own hands

While here is the same example using reprex::reprex() (no output):

logger::log_warn("foobar")

Created on 2023-10-22 with reprex v2.0.2

I have no idea if this is related, but it seems that reprex::reprex() is not allowing the use of globalCallingHandlers():

logger::log_warnings()
#> Error in globalCallingHandlers(warning = function(m) {: should not be called with handlers on the stack

Created on 2023-10-22 with reprex v2.0.2

daroczig commented 11 months ago

Thanks for reporting this!

I think this is due to reprex not showing the stderr that is used by default for logging, but when setting that to stdout as part of the reprex, it shows up, see e.g.:

library(logger);log_appender(appender_stdout); log_info(42)
#> INFO [2023-10-23 23:25:06] 42

Created on 2023-10-23 with reprex v2.0.2

Another option might be to use the std_out_err option of reprex, resulting in:

logger::log_info(42)

Created on 2023-10-23 with reprex v2.0.2

Standard output and standard error ``` sh INFO [2023-10-23 23:26:20] 42 ```
DanChaltiel commented 11 months ago

Nice!

It seems you are not using issues templates, but if this solves the problem maybe you could put this in a Bug issue template?

Something like:

Please include a reprex using reprex::reprex(std_out_err=...)

daroczig commented 11 months ago

great idea, thanks!