A versatile tool for logging in manageable pieces.
Chainsaw is a Clojure library for logging datastructures with taoensso/timbre
. It also comes with an Elastiscsearch appender to improve the usability of your data driven logging.
This library was inspired by the Juxt blogpost Logging: change your mind from 2016. It outlines the reasons for data driven logging, and how one could go about adopting it. Chainsaw was conceived as a implementation for this concept.
[com.alliander.chainsaw/core "0.1.0"]
(require '[com.alliander.chainsaw.core :as logd]
'[taoensso.timbre :as log])
(logd/errord ::http-request.failed {:request request :response response})
(let [user-id (:user-id request)]
;; log the user-id from now on, conventional timbre style
(log/with-context {:user-id user-id}
(logd/infod ::service.called)
(if-let [service-level (service-level user-id)]
;; add the service level to the logging context
(logd/with-merged-context {:service-level service-level}
(logd/info ::service-level.found)
(service service-level))
;; per-logging statement context
(do (logd/error ::service-level.not-found {:request request})
(reject))))))
;; exceptions should be passed as the first argument
(logd/error e ::exception)
Copyright 2017 Alliander NV.
Licensed under the Apache Public License 2.0.