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

appender_tee is showing some wrong outsputs in file but correct outputs in console #65

Closed schmalte04 closed 3 years ago

schmalte04 commented 3 years ago

Hi, i am currently working on implementing the logger package into production. The following code causes some strange numbers and signs when the code is executed manually in RStudio. If i use it from a cronjob it looks fine.

Here is the basic code:

log_layout(layout_glue_colors)
  file_name<-paste0("log_files/Trading_Log_",Sys.Date(),".log")
  log_appender(appender_tee(file_name))
  log_info('Starting Script')

Here is the file output

INFO [2020-10-28 17:17:03] Starting Script

Any ideas? Just updated to version 0.2 via Github still these issues. I am using R version 4.0.0 (2020-04-24) -- "Arbor Day"

daroczig commented 3 years ago

Can you please share your sessionInfo()? Mostly interested in the local settings.

schmalte04 commented 3 years ago

That the locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8+

version 4.0.0 (2020-04-24) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Mojave 10.14.4

More info needed?

daroczig commented 3 years ago

Actually, I realized what's the problem even without the local info, sorry for the extra cycle.

So you are using the colorized layout, which is using ASCII escape codes for the coloring. Writing that to a file will include the ASCII escape characters -- that's what you see there. To open such a file, you would need eg less -R or similar, as most text editors do not understand ASCII color codes.

To overcome this issue, what I'd rather do: if you need colorized layout in console and want to log into a file as well (without colors), then forget about appender_tee and set up two loggers using the index feature. Set up layout_glue_colors for the console, and use a different layout for the file appended.

I hope this makes sense, so I'm closing the ticket, but let me know if there's any question.

schmalte04 commented 3 years ago

Perfect, thank you!