Add unique id (uuid) on each log entry

This commit is contained in:
Andrey Antukh 2022-02-16 11:58:43 +01:00
parent e8426006e3
commit 256ed7410f
2 changed files with 7 additions and 6 deletions

View file

@ -49,7 +49,7 @@
(assoc :host (cf/get :host))
(assoc :public-uri (cf/get :public-uri))
(assoc :version (:full cf/version))
(assoc :id (uuid/next))))
(update :id #(or % (uuid/next)))))
(defn handle-event
[{:keys [executor] :as cfg} event]

View file

@ -7,6 +7,7 @@
(ns app.common.logging
(:require
[app.common.exceptions :as ex]
[app.common.uuid :as uuid]
[clojure.pprint :refer [pprint]]
[cuerdas.core :as str]
[fipp.edn :as fpp]
@ -35,12 +36,12 @@
(reduce-kv #(.with ^MapMessage %1 (name %2) %3) message m))))
#?(:clj
(def logger-context
(LogManager/getContext false)))
(def logger-context
(LogManager/getContext false)))
#?(:clj
(def logging-agent
(agent nil :error-mode :continue)))
(def logging-agent
(agent nil :error-mode :continue)))
(defn- simple-prune
([s] (simple-prune s (* 1024 1024)))
@ -175,7 +176,7 @@
`(->> (ThreadContext/getImmutableContext)
(send-off logging-agent
(fn [_# cdata#]
(with-context (-> {} (into cdata#) (into ~context))
(with-context (-> {:id (uuid/next)} (into cdata#) (into ~context))
(->> (or ~raw (build-map-message ~props))
(write-log! ~logger-sym ~level-sym ~cause))))))