lewinfox / icecream

Never use `print()` to debug again.
http://www.lewinfox.com/icecream/
Other
52 stars 6 forks source link

Using icecream with logging #25

Open vorpalvorpal opened 10 months ago

vorpalvorpal commented 10 months ago

I've just discovered icecream and am utterly blown away! Utterly blown away!

I had made my own logging function that worked with the {logger} package that was a much inferior version of icecream::ic but which sent the output to a logging file rather than to the console.

I can partially recreate this behaviour with the following:

log_ic <- function(...) {
  ic_output <- capture.output(ic(...), type = "message")
  logger::log_level(level = getOption("log_level"), logger::skip_formatter(ic_output))
}

However this writes the following to the log file:

ℹ ic: `withVisible()` in <env: global> | `foo`:
bar

which gets the context incorrect.

Is there a way to use ic() with logging and/or would you consider adding a log_ic function (or similar) that could interoperate with logging packages?

lewinfox commented 10 months ago

Hi, thanks for your interest and kind words. Delighted to hear you like the package!

I'm against building bespoke logging functionality into the package - lots of effort to build and maintain, and we'd be building an inferior version of functionality that already exists in other packages.

However, I can see value in allowing ic to work with pre-existing logging packages. I haven't used any myself so I'm not sure quite how that would work!

If you want to take a crack at it I'd be happy to review a PR and answer any questions about the icecream code. If I find myself with free time I may have a go as well, but that's unlikely in the near term.