From 256ed7410f33832ee65b514735e6c92d1c3d1982 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 16 Feb 2022 11:58:43 +0100 Subject: [PATCH] :sparkles: Add unique id (uuid) on each log entry --- backend/src/app/loggers/database.clj | 2 +- common/src/app/common/logging.cljc | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/src/app/loggers/database.clj b/backend/src/app/loggers/database.clj index d4e339100..734eae460 100644 --- a/backend/src/app/loggers/database.clj +++ b/backend/src/app/loggers/database.clj @@ -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] diff --git a/common/src/app/common/logging.cljc b/common/src/app/common/logging.cljc index b9331834c..09febd1d3 100644 --- a/common/src/app/common/logging.cljc +++ b/common/src/app/common/logging.cljc @@ -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))))))