daroczig / logger

A lightweight, modern and flexible, log4j and futile.logger inspired logging utility for R
https://daroczig.github.io/logger
285 stars 42 forks source link

Calling `logger::log_{appender, threshold, layout, formatter}` functions via `do.call` fails #120

Closed averissimo closed 11 months ago

averissimo commented 1 year ago

Found an edge case when testing a package against the master branch of this repository.

It works fine with current release v0.2.2, but fails against master

testthat::test_that("logger::log_appender `do.call` works the same as calling function", {
  t <- withr::local_tempfile()

  old_appender <- log_appender()

  do.call(
    logger::log_appender,
    list(
      logger::appender_file(t)
    )
  ) |>
    testthat::expect_no_error()

  logger::log_info("42")

  testthat::expect_length(readLines(t), 1)

  log_appender(old_appender)
})

testthat::test_that("logger::log_threshold `do.call` works the same as calling function", {
  old_threshold <- logger::log_threshold()

  do.call(
    logger::log_threshold, 
    list(
      logger::WARN
    )
  ) |> 
    testthat::expect_no_error()

  logger::log_info("42")

  logger::log_threshold(old_threshold)
})
daroczig commented 11 months ago

Thanks for reporting this! Could you please check if #125 solves the problem? Would appreciate a review on the PR.