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

Logging format in R packages #118

Closed corey-dawson closed 11 months ago

corey-dawson commented 1 year ago

I want to use this logging solution inside a package I am building. I am seeing an issue where the package is not using the format I've specified, after I build and install the package. See sample below:

# setup logger
# ==========================================================================
pkglog <- logger::layout_glue_generator(format = '{time} | {level} | mypkg | {sys.call(1)[[1]]} | {msg}')
logger::log_layout(pkglog, namespace = 'pkg')
logger::log_threshold(logger::INFO, namespace = 'pkg')

#' function to decode base64 encoded strings
#' @param encoded_str base84 encoded string to decode
#' @return decoded string
#' @keywords internal
#' @examples
#' mypass <- decode(encoded_str = "bXlwYXNzCg==")
#' @export
decode <- function(encoded_str){
  decoded <- trimws(rawToChar(openssl::base64_decode(encoded_str)))
  logger::log_info("Decoded", namespace="pkg")
  return(decoded)
}

image

If I create this function ad-hoc (not within a package) with same format, I get the desired output

image

Any direction would be helpful. thanks in advance.

daroczig commented 1 year ago

You don't necessarily need to set the namespace inside of a package: it will be the package name itself by default -- but of course you should be able to set that to something custom if needed.

Not sure what is wrong there, it should work, and it worked in a minimal reproducible example I set up locally. Can you try importing log_info instead of the double-colon approach?

If you can share your repo, I'm happy to take a closer look.

daroczig commented 11 months ago

Please reopen with more info as per above.