|
1 | 1 | (ns com.moclojer.components.logs |
2 | 2 | (:require |
3 | | - [com.moclojer.components.logs :as logs] |
4 | 3 | [com.stuartsierra.component :as component] |
5 | 4 | [clojure.core.async :as async] |
6 | 5 | [clojure.data.json :as json] |
|
34 | 33 |
|
35 | 34 | (defn signal->opensearch-log |
36 | 35 | "Adapts a telemere signal to a pre-defined schema for OpenSearch." |
37 | | - [{:keys [thread location] :as signal}] |
38 | | - (-> (select-keys signal [:level :ctx :data :msg_ :uid :inst]) |
39 | | - (merge {"thread/group" (:group thread) |
| 36 | + [{:keys [thread location parent root msg_] :as signal}] |
| 37 | + (-> (select-keys signal [:level :ctx :data :uid :id |
| 38 | + :inst :end-inst :run-nsecs]) |
| 39 | + (merge {"msg_" (when-not (delay? msg_) msg_) |
| 40 | + "thread/group" (:group thread) |
40 | 41 | "thread/name" (:name thread) |
41 | 42 | "thread/id" (:id thread) |
| 43 | + "parent/uid" (:uid parent) |
| 44 | + "parent/id" (:id parent) |
| 45 | + "root/uid" (:uid root) |
| 46 | + "root/id" (:id root) |
42 | 47 | "location" (str (:ns location) ":" |
43 | 48 | (:line location) "x" |
44 | 49 | (:column location))}) |
|
99 | 104 | (t/remove-handler! ::opensearch) |
100 | 105 | (update this :log-ch #(when % (async/close! %))))) |
101 | 106 |
|
| 107 | +(defmacro trace |
| 108 | + [id data & body] |
| 109 | + `(taoensso.telemere/trace! |
| 110 | + {:id ~id |
| 111 | + :data ~data} |
| 112 | + (do ~@body))) |
| 113 | + |
102 | 114 | (defn log |
103 | 115 | [level msg & [data ctx error]] |
104 | 116 | (t/log! {:level level |
|
111 | 123 | {:cid (str "cid-" (random-uuid) "-" (System/currentTimeMillis))}) |
112 | 124 |
|
113 | 125 | (comment |
114 | | - (component/start |
115 | | - (map->Logger |
116 | | - {:config |
117 | | - {:env :prod |
118 | | - :opensearch |
119 | | - {:username "foobar" |
120 | | - :password "foobar" |
121 | | - :host "foobar" |
122 | | - :port 25060 |
123 | | - :index "components-test-logs"}}})) |
124 | | - |
125 | | - (log :error "something happened" {:hello true}) |
| 126 | + (def logger |
| 127 | + (map->Logger |
| 128 | + {:config |
| 129 | + {:env :prod |
| 130 | + :opensearch |
| 131 | + {:username "foobar" |
| 132 | + :password "foobar" |
| 133 | + :host "foobar" |
| 134 | + :port 25060 |
| 135 | + :index "components-test-logs"}}})) |
| 136 | + |
| 137 | + (component/start logger) |
| 138 | + (component/stop logger) |
| 139 | + |
| 140 | + (trace ::testing-stuff {:testing? :definitely} |
| 141 | + (log :error "aaaaa aaaa" {:hello true})) |
126 | 142 | ;; |
127 | 143 | ) |
0 commit comments