/
aml.clj
91 lines (71 loc) · 2.26 KB
/
aml.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(ns metrix-lawg.logger.impl.aml
(:import [metrix_lawg.core TimeMetric
SuccessMetric
ErrorMetric
ExitCodeMetric])
(:gen-class))
(defn add-meta
[metric metadata]
(if metadata (assoc metric :metadata metadata) metric))
;; ================
;; * Interfaces *
;; ================
(defprotocol IApplicationLogger
(runtime [this action value]
[this action value metadata])
(success [this action]
[this action metadata])
(failure [this action]
[this action metadata])
(error [this action value]
[this action value metadata])
(exit-code [this action value]
[this action value metadata]))
;; ==================
;; * Record Impls *
;; ==================
;; ------------------------------------
;; - Generic Logger (Action Agnostic) -
;; ------------------------------------
(defrecord ApplicationMetricLogger [app writer]
IApplicationLogger
(runtime
[this action value]
(let [metric (TimeMetric. app action)]
(.write writer metric value)))
(runtime
[this action value metadata]
(let [metric (TimeMetric. app action)]
(.write writer (add-meta metric metadata) value)))
(success
[this action]
(let [metric (SuccessMetric. app action)]
(.write writer metric 1)))
(success
[this action metadata]
(let [metric (SuccessMetric. app action)]
(.write writer (add-meta metric metadata) 1)))
(failure
[this action]
(let [metric (SuccessMetric. app action)]
(.write writer metric 0)))
(failure
[this action metadata]
(let [metric (SuccessMetric. app action)]
(.write writer (add-meta metric metadata) 0)))
(error
[this action value]
(let [metric (ErrorMetric. app action value)]
(.write writer metric 1)))
(error
[this action value metadata]
(let [metric (ErrorMetric. app action value)]
(.write writer (add-meta metric metadata) 1)))
(exit-code
[this action value]
(let [metric (ExitCodeMetric. app action)]
(.write writer metric value)))
(exit-code
[this action value metadata]
(let [metric (ExitCodeMetric. app action)]
(.write writer (add-meta metric metadata) value))))