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

logger (version 0.3.0) is causing a problem when used with jsonlite and plumber #156

Closed vipulg13 closed 1 month ago

vipulg13 commented 1 month ago

Hello, I have a shiny application, which is making a call to a backend function exposed via Plumber API POST method. In the backend function, I am using logger::log_info() to log certain information. The backend function does its job and the log_info() also successfully makes an entry in the log file. However, the API call fails to send the response body back, which is anyway return() in my case. This eventually causes the application to crash. Upon checking the docker logs, I see the following error:

Error in run_now(check_time, all = FALSE) : Index out of bounds: [index='status']. Calls: -> invokeCppCallback Please note that I still have to work on writing an MRE, however, I decided to submit this issue because the above mentioned problem gets resolved when version '0.2.2' is used instead of '0.3.0'. The problem seems to be specific with the latter version. The behaviour can be reproduced with 'jsonlite 1.8.8' and 'plumber 1.2.2'.
daroczig commented 1 month ago

v0.3 was a significant update, see https://github.com/daroczig/logger/blob/master/NEWS.md

The related change is that the log fns now return a logger object instead of NULL. I'm not familiar with your backend fn, and if needs to return anything, but to overcome the issue, either return NULL after calling the log function, or process the logger object, e.g. use some of its fields (maybe the log message or record).

I'm closing as cannot really help without a MRE, but please reopen and I'll be happy to take a look.