Skip to content

Commit

Permalink
[mod] Refactor, improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Mar 7, 2023
1 parent 67df9b7 commit e6cdf99
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 122 deletions.
15 changes: 9 additions & 6 deletions example-project/src/example/client.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
(:require-macros
[cljs.core.async.macros :as asyncm :refer [go go-loop]]))

;; (timbre/set-level! :trace) ; Uncomment for more logging
;;;; Logging config

(sente/set-min-log-level! :info) ; Min log level for internal Sente namespaces
(timbre/set-ns-min-level! :info) ; Min log level for this namespace

;;;; Util for logging output to on-screen console

(def output-el (.getElementById js/document "output"))
(defn ->output! [fmt & args]
(let [msg (apply encore/format fmt args)]
(timbre/debugf "->output: %s" msg)
(aset output-el "value" (str "" (.-value output-el) "\n" msg))
;; (timbre/tracef "->output: %s" msg)
(aset output-el "value" (str (.-value output-el) "\n" msg))
(aset output-el "scrollTop" (.-scrollHeight output-el))))

(->output! "ClojureScript appears to have loaded correctly.")
Expand Down Expand Up @@ -140,13 +143,13 @@
(when-let [target-el (.getElementById js/document "btn5")]
(.addEventListener target-el "click"
(fn [ev]
(->output! "Disconnecting")
(->output! "Disconnecting...\n\n")
(sente/chsk-disconnect! chsk))))

(when-let [target-el (.getElementById js/document "btn6")]
(.addEventListener target-el "click"
(fn [ev]
(->output! "Reconnecting")
(->output! "Reconnecting...\n\n")
(sente/chsk-reconnect! chsk))))

(when-let [target-el (.getElementById js/document "btn-login")]
Expand All @@ -156,7 +159,7 @@
(if (str/blank? user-id)
(js/alert "Please enter a user-id first")
(do
(->output! "Logging in with user-id %s" user-id)
(->output! "Logging in with user-id %s...\n\n" user-id)

;;; Use any login procedure you'd like. Here we'll trigger an Ajax
;;; POST request that resets our server-side session. Then we ask
Expand Down
6 changes: 4 additions & 2 deletions example-project/src/example/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
;; Optional, for Transit encoding:
[taoensso.sente.packers.transit :as sente-transit]))

;; (timbre/set-level! :trace) ; Uncomment for more logging
;; (reset! sente/debug-mode?_ true) ; Uncomment for extra debug info
;;;; Logging config

(sente/set-min-log-level! :info) ; Min log level for internal Sente namespaces
(timbre/set-ns-min-level! :info) ; Min log level for this namespace

;;;; Define our Sente channel socket (chsk) server

Expand Down
Loading

0 comments on commit e6cdf99

Please sign in to comment.