Module to setup proper logging infrastructure.
We log using timbre.
We use structured logging writing JSON log messages to a log file which then can be tailed by a log agent and sent to your logging infrastructure.
Also, it sets up collecting messages from different logging libraries using SLF4J, so no matter what logging library a third party is using, you only configure logging in one place.
Supported logging libraries:
Setup logging sets up handling of uncaught exceptions, so no exception goes by unnoticed anymore. Also, it captures elements not serializable to JSON.
In a library, you may choose whichever logging library you want to use, as long as it's supported by setup logging in the application using that library.
We strongly advise to use timbre.
However, as you want to configure logging for the REPL used to develop the library or the tests running, you can use setup logging as follows:
Add com.taoensso/timbre {:mvn/version "5.2.1"} to your deps.edn :deps map.
Also, add this project to your deps.edn as dev or test :extra-deps. In Bauhaus itself, this is possible from the local repository structure using
:aliases {:dev {:extra-deps {org.gorillalabs.bauhaus/setup-logging {:local/root "../../modules/setup/logging"}}}}or using git coordinates like this, but with the latest :git/sha
{ ...
org.gorillalabs.bauhaus/setup-logging {:git/url "git@github.com:gorillalabs/bauhaus.git"
:git/sha "AE...<commit sha>"
:deps/root "modules/setup/logging"}
...}After REPL startup (or before running tests), call gorillalabs.bauhaus.setup.log/init-dev-logging which will setup simple message logging to the console.
Add this project to your deps.edn. In the Bauhaus project itself, this is possible from the local repository structure using
{:deps {...
org.gorillalabs.bauhaus/setup-logging {:local/root "../../modules/setup/logging"}
...
}}or using git coordinates like this, but with the latest :git/sha
{ ...
org.gorillalabs.bauhaus/setup-logging {:git/url "git@github.com:gorillalabs/bauhaus.git"
:git/sha "AE...<commit sha>"
:deps/root "modules/setup/logging"}
...}To configure clojure/tools.logging, you need to run your code with the System property -Dclojure.tools.logging.factory=clojure.tools.logging.impl/slf4j-factory set (see Selecting a logging implementation).
During system startup, call gorillalabs.bauhaus.setup.log/init-logging with the location of your (rotating) logfile.
Alternatively, there's gorillalabs.bauhaus.setup.log/init-dev-logging which will use simple message logging to the console.
Require [taoensso.timbre :as log] and use timbre just as it's supposed to be used.
You might also use any other logging API, but we recommend using timbre for our code.
You can change logging configuration at any point in time using timbre's (log/merge-config! new-config).