rexyai / RestRserve

R web API framework for building high-performance microservices and app backends
https://restrserve.org
271 stars 31 forks source link

Is there a way to pass file arguement to the logger printer function #169

Closed vikram-rawat closed 3 years ago

vikram-rawat commented 3 years ago
 set_printer = function(FUN = NULL) {
      if (is.null(FUN)) {
        FUN = function(timestamp, level, logger_name, pid, message, ...) {
          log_msg = list(
            timestamp = format(timestamp, "%Y-%m-%d %H:%M:%OS6"),
            level = as.character(level),
            name = as.character(logger_name),
            pid = as.integer(pid),
            msg = message
          )
          extra = list(...)
          if (length(extra) > 0) {
            log_msg = c(log_msg, extra)
          }
          x = to_json(log_msg)
          cat(x, file = "", append = TRUE, sep = "\n")
        }
      }

This function is more than enough for every need but how would pass file argument to the cat function.

cat(x, file = "", append = TRUE, sep = "\n")

Is there a way to pass this argument ??

dselivanov commented 3 years ago

Please consider asking question on stack-overflow as suggested in CONTRIBUTING

Why would you need to pass file argument at each invocation of the printer? It looks you are trying to solve some non-existent problem (or at least very weird). You can use ?sink to redirect output to the file.

Generally it makes sense to use lgr package for user-level logging. Built-in logger has the same interface as lgr.

vikram-rawat commented 3 years ago

To me logging is writing down which request has been processed at what URL with what result status. Like

Post URL 200 date

Something I am familiar with other languages.

Now I am really curious what does the logger do...

Because after the server starts I don't see any log printed even on the screen and the documentation is not clear on that part. It only talk about how to do it manually while testing.

Is there a way i can get that output in a file???

dselivanov commented 3 years ago

To me logging is writing down which request has been processed at what URL with what result status. Like Post URL 200 date

Have you tried application$logger$set_log_level("debug")?

Is there a way i can get that output in a file???

You can either:

vikram-rawat commented 3 years ago

This command actually helped a lot. thanks for replying.

application$logger$set_log_level("debug")

Sorry to bug you for such a simple query. I thought There should be a way to pass file argument in the function. but this will work too..

I could have asked the question on StackOverflow. but it doesn't allow me to ask questions. Is it possible to ask questions on community.rstudio.com?

those questions will actually help people googling with the same problem later on.

Thanks again.. :-)