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?
clojure.tools.logging
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.
This simple? I don't need to provide anything besides?
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.
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
(`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)
Thank you very much, this answers all my questions regarding the subject 🙏