Do package developers use logging packages?

I'm considering using one of the many logging packages to help debug one of my own packages, but a quick browse of CRAN suggests that not many others do this. For example, debugme, which is in the r-lib organisation, has only 3 reverse imports, and 4 reverse suggests.

Do the maintainers of major packages (e.g. tidyverse) not use loggers? Do they use them, but somehow avoid them as a CRAN dependency? What are the alternatives?

1 Like

I may be misunderstanding your question, but typically debugging is an interactive technique used by a package developer during the package development stage. Why would you want to include a debugger as a package dependency? Do you have a compelling use-case?

My question is about logging packages, not about debugging packages, although logging packages are often used as part of debugging.

Messages that are written to a log are defined in the code, so there's no way to avoid them becoming part of the codebase. Maybe it's possible to avoid making it a package dependency (part of my question), but only if you don't mind users being unable to activate logging when reporting an issue.

For reference, the debugme README says, "To use debugme in your package, import it, and then add the following .onLoad function to your package", so I think it is intended to be a dependency.

Logging is different than debugging, in my opinion. Though, as you say, logs can sometimes be helpful to debug an issue.

Logging packages definitely gets used in various packages. Personally, I like the log4r package, but there are other good options like logger, futile.logger, logging, and many more.

Thank you for replying @mattwarkentin but I think you are still misunderstanding the questions. I will try again to clarify.

I thought that using a logger was good practice, yet hardly any CRAN packages include logging packages in Depends or Suggests. That seems to imply that hardly any package maintainers use loggers. Are the maintainers somehow hiding the dependencies from CRAN? If not, are they doing something else instead of logging? Or is logging not best practice?

No, you can't hide dependencies. If a logger isn't listed as part of the Imports, Depends, or Suggests, then that package isn't using an external logging package.

In my experience, not that many packages write logs to disk. Messages, warnings, and errors printed to the console are more common.

Logging is most beneficial for long running programs on remote systems that are difficult or impossible to use with a interactive debugger. So retroactively inspecting the logs is one of the only ways to monitor or debug issues.

However most R packages are run on a local system where you can readily use R's built in interactive debugger, or attach a C level debugger like gdb or lldb. Furthermore adding the logging code has a non-negligible performance impact in R code. The logging code also requires additional maintenance to maintain.

We feel the cost tradeoff to add logging generally not worthwhile for most of the R packages we maintain. But of course other developers may decide differently for their projects.


(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)