Fork me on GitHub
#observability
<
2020-07-07
>
Ben Sless17:07:23

Hi all, What are the best practices regarding adding logging to libraries? How do I make logging backends pluggable from the user end while providing a sane default?

seancorfield17:07:04

clojure.tools.logging

seancorfield17:07:41

It provides a simple wrapper over a wide range of (Java) logging libraries in a way that lets users of your library control the implementation.

Ben Sless17:07:46

This simple? I don't need to provide anything besides?

seancorfield17:07:23

Yup, you'll want to provide an implementation as a dependency in your tests for the library locally, and you'll want to note in the README that your library uses clojure.tools.logging and expects users to provide an implementation.

seancorfield17:07:33

For example, with next.jdbc, I have this in my :test alias to select an implementation for my tests: https://github.com/seancorfield/next-jdbc/blob/develop/deps.edn#L28-L35

seancorfield17:07:24

(`next.jdbc` does not actually depend on org.clojure/tools.logging for day-to-day use, only for testing, but the principle is the same: you need an implementation for testing, but users can choose a different implementation)

Ben Sless18:07:02

Thank you very much, this answers all my questions regarding the subject 🙏