Skip to content

Commit 94b529d

Browse files
committed
feat(loggin): bring back portal + mulog
1 parent f975bfa commit 94b529d

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

deps.edn

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525

2626
ring/ring-mock {:mvn/version "0.4.0"}
2727

28-
;; Logging
28+
;; Logging and observability
2929
org.slf4j/slf4j-simple {:mvn/version "2.0.16"}
3030
com.brunobonacci/mulog {:mvn/version "0.9.0"}
31+
djblue/portal {:mvn/version "0.58.5"}
32+
3133
;;
3234
;; A small library for explicit, intentful configuration.
3335
;; https://github.com/juxt/aero

src/dev/mulog_events.clj

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(ns mulog-events
2+
(:require
3+
[com.brunobonacci.mulog :as mulog]
4+
[com.brunobonacci.mulog.buffer :as mulog-buffer]))
5+
6+
;; ---------------------------------------------------------
7+
;; Set event global context
8+
;; - information added to every event for REPL workflow
9+
;; (mulog/set-global-context! {:app-name "parts"
10+
;; :version "0.1.0-SNAPSHOT", :env "dev"})
11+
;; ---------------------------------------------------------
12+
13+
;; ---------------------------------------------------------
14+
;; Mulog event publishing
15+
16+
(deftype TapPublisher
17+
[buffer transform]
18+
com.brunobonacci.mulog.publisher.PPublisher
19+
(agent-buffer [_] buffer)
20+
(publish-delay [_] 200)
21+
(publish [_ buffer]
22+
(doseq [item (transform (map second (mulog-buffer/items buffer)))]
23+
(tap> item))
24+
(mulog-buffer/clear buffer)))
25+
26+
#_{:clj-kondo/ignore [:unused-private-var]}
27+
(defn ^:private tap-events
28+
[{:keys [transform] :as _config}]
29+
(TapPublisher. (mulog-buffer/agent-buffer 10000) (or transform identity)))
30+
31+
(def tap-publisher
32+
"Start mulog custom tap publisher to send all events to Portal
33+
and other tap sources
34+
`mulog-tap-publisher` to stop publisher"
35+
(mulog/start-publisher!
36+
{:type :custom, :fqn-function "mulog-events/tap-events"}))
37+
38+
#_{:clj-kondo/ignore [:unused-public-var]}
39+
(defn stop
40+
"Stop mulog tap publisher to ensure multiple publishers are not started
41+
Recommended before using `(restart)` or evaluating the `user` namespace"
42+
[]
43+
tap-publisher)

src/dev/repl.clj

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[kaocha.repl :as k]
44
[kaocha.watch :as watch]
55
[migratus.core :as migratus]
6+
[portal.api :as portal]
7+
[mulog-events]
68
[parts.config :as conf]
79
[parts.db :as db]
810
[parts.server :as server]
@@ -12,10 +14,20 @@
1214
(defn cljs-repl []
1315
(shadow.cljs.devtools.api/repl :frontend))
1416

17+
(def portal-instance
18+
"Open portal window if no portal sessions have been created.
19+
A portal session is created when opening a portal window.
20+
21+
Opens in the default system browser."
22+
(or (seq (portal/sessions))
23+
(portal/open {:app false})))
24+
25+
(add-tap #'portal.api/submit)
26+
1527
;; App server management
1628

1729
(defonce server-ref (atom nil))
18-
;; TODO: Do we also want to open Inspector automatically?
30+
1931
(defn start []
2032
(shadow-server/start!)
2133
(shadow/watch :frontend)

src/main/parts/server.clj

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
(:require
77
[clojure.core.async :as async]
88
[com.brunobonacci.mulog :as mulog]
9+
[muuntaja.core :as muuntaja]
910
[org.httpkit.server :as server]
1011
[parts.api.account :as api.account]
1112
[parts.api.auth :as api.auth]
1213
[parts.api.systems :as api.systems]
1314
[parts.auth :as auth]
15+
[parts.config :as conf]
1416
[parts.db :as db]
1517
[parts.handlers.pages :as pages]
1618
[parts.handlers.waitlist :as waitlist]
@@ -19,7 +21,6 @@
1921
[reitit.ring :as ring]
2022
[reitit.ring.coercion :as rrc]
2123
[reitit.ring.middleware.muuntaja :as muuntaja-middleware]
22-
[muuntaja.core :as muuntaja]
2324
[ring.middleware.params :refer [wrap-params]])
2425
(:gen-class))
2526

@@ -193,7 +194,7 @@
193194
(let [port (or (some-> (first args) Integer/parseInt) 3000)]
194195
;; Set up global logging context
195196
(mulog/set-global-context!
196-
{:app-name "Parts" :version "0.1.0-SNAPSHOT"})
197+
{:app-name "Parts" :version "0.1.0-SNAPSHOT", :env (conf/get-environment)})
197198
(mulog/log ::application-startup :arguments args :port port)
198199

199200
;; Initialize database

0 commit comments

Comments
 (0)