daroczig/logger

Logging format in R packages

corey-dawson opened this issue · 2 comments

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.

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.

Please reopen with more info as per above.