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 :host (cf/get :host))
(assoc :public-uri (cf/get :public-uri)) (assoc :public-uri (cf/get :public-uri))
(assoc :version (:full cf/version)) (assoc :version (:full cf/version))
(assoc :id (uuid/next)))) (update :id #(or % (uuid/next)))))
(defn handle-event (defn handle-event
[{:keys [executor] :as cfg} event] [{:keys [executor] :as cfg} event]

View file

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