-
Notifications
You must be signed in to change notification settings - Fork 47
/
console_json.clj
36 lines (24 loc) · 1.16 KB
/
console_json.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
(ns com.brunobonacci.mulog.publishers.console-json
(:require [com.brunobonacci.mulog.publisher :as p]
[com.brunobonacci.mulog.buffer :as rb]
[com.brunobonacci.mulog.common.json :as json]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; ----==| J S O N C O N S O L E |==---- ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(deftype JsonConsolePublisher [config buffer transform]
com.brunobonacci.mulog.publisher.PPublisher
(agent-buffer [_]
buffer)
(publish-delay [_]
200)
(publish [_ buffer]
;; items are pairs [offset <item>]
(doseq [item (transform (map second (rb/items buffer)))]
(printf "%s\n" (json/to-json item (select-keys config [:pretty?]))))
(flush)
(rb/clear buffer)))
(defn json-console-publisher
[{:keys [transform pretty?] :as config}]
(JsonConsolePublisher. config (rb/agent-buffer 10000) (or transform identity)))