-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minimal: refactor dev section similar to other templates
- add portal.clj to start portal data inspector - add `mulog_events.clj` to define tap publisher and start publishing events to portal - refactor `user.clj` namespace, mulog and portal sections
- Loading branch information
1 parent
ae33c07
commit 36cfc4a
Showing
4 changed files
with
94 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
;; --------------------------------------------------------- | ||
;; Mulog Global Context and Custom Publisher | ||
;; | ||
;; - set event log global context | ||
;; - tap publisher for use with Portal and other tap sources | ||
;; - publish all mulog events to Portal tap source | ||
;; --------------------------------------------------------- | ||
|
||
(ns mulog-events | ||
(:require | ||
[com.brunobonacci.mulog :as mulog] | ||
[com.brunobonacci.mulog.buffer :as mulog-buffer])) | ||
|
||
;; --------------------------------------------------------- | ||
;; Set event global context | ||
;; - information added to every event for REPL workflow | ||
(mulog/set-global-context! {:app-name "{{main/ns}} Service", | ||
:version "0.1.0", :env "dev"}) | ||
;; --------------------------------------------------------- | ||
|
||
;; --------------------------------------------------------- | ||
;; Mulog event publishing | ||
|
||
(deftype TapPublisher | ||
[buffer transform] | ||
com.brunobonacci.mulog.publisher.PPublisher | ||
(agent-buffer [_] buffer) | ||
(publish-delay [_] 200) | ||
(publish [_ buffer] | ||
(doseq [item (transform (map second (mulog-buffer/items buffer)))] | ||
(tap> item)) | ||
(mulog-buffer/clear buffer))) | ||
|
||
#_{:clj-kondo/ignore [:unused-private-var]} | ||
(defn ^:private tap-events | ||
[{:keys [transform] :as _config}] | ||
(TapPublisher. (mulog-buffer/agent-buffer 10000) (or transform identity))) | ||
|
||
(def tap-publisher | ||
"Start mulog custom tap publisher to send all events to Portal | ||
and other tap sources | ||
`mulog-tap-publisher` to stop publisher" | ||
(mulog/start-publisher! | ||
{:type :custom, :fqn-function "mulog-events/tap-events"})) | ||
|
||
#_{:clj-kondo/ignore [:unused-public-var]} | ||
(defn stop | ||
"Stop mulog tap publisher to ensure multiple publishers are not started | ||
Recommended before using `(restart)` or evaluating the `user` namespace" | ||
[] | ||
tap-publisher) | ||
|
||
;; Example mulog event message | ||
;; (mulog/log ::dev-user-ns :message "Example event message" :ns (ns-publics *ns*)) | ||
;; --------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(ns portal | ||
(:require | ||
;; Data inspector | ||
[portal.api :as inspect])) | ||
|
||
|
||
;; --------------------------------------------------------- | ||
;; Start Portal and capture all evaluation results | ||
|
||
;; Open Portal window in browser with dark theme | ||
;; https://cljdoc.org/d/djblue/portal/0.37.1/doc/ui-concepts/themes | ||
;; Portal options: | ||
;; - light theme {:portal.colors/theme :portal.colors/solarized-light} | ||
;; - dark theme {:portal.colors/theme :portal.colors/gruvbox} | ||
|
||
(def instance | ||
"Open portal window if no portal sessions have been created. | ||
A portal session is created when opening a portal window" | ||
(or (seq (inspect/sessions)) | ||
(inspect/open {:portal.colors/theme :portal.colors/gruvbox}))) | ||
|
||
;; Add portal as tapsource (add to clojure.core/tapset) | ||
(add-tap #'portal.api/submit) | ||
;; --------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters