refactoring cljs logging to Closure (goog.log)
This commit is contained in:
parent
7fe4541e90
commit
0644b02703
3 changed files with 22 additions and 12 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 227 KiB |
|
|
@ -1,7 +1,9 @@
|
|||
(ns mount.core
|
||||
#?(:clj (:require [mount.tools.macro :refer [on-error throw-runtime] :as macro]
|
||||
[mount.tools.logger :refer [log]]
|
||||
[clojure.string :as s])
|
||||
:cljs (:require [mount.tools.macro :as macro]))
|
||||
:cljs (:require [mount.tools.macro :as macro]
|
||||
[mount.tools.logger :refer [log]]))
|
||||
#?(:cljs (:require-macros [mount.core]
|
||||
[mount.tools.macro :refer [if-clj on-error throw-runtime]])))
|
||||
|
||||
|
|
@ -51,9 +53,7 @@
|
|||
[state]
|
||||
(when-let [{:keys [stop] :as up} (@running state)]
|
||||
(when stop
|
||||
(let [note (str "<< stopping.. " state " (namespace was recompiled)")]
|
||||
#?(:clj (prn note)
|
||||
:cljs (.log js/console note)))
|
||||
(log (str "<< stopping.. " state " (namespace was recompiled)"))
|
||||
(stop))
|
||||
(swap! running dissoc state)))
|
||||
|
||||
|
|
@ -131,14 +131,6 @@
|
|||
(up name state (atom #{})))
|
||||
@inst)))
|
||||
|
||||
#?(:clj
|
||||
(defn log [msg]
|
||||
(prn msg)))
|
||||
|
||||
#?(:cljs
|
||||
(defn log [msg]
|
||||
(.log js/console msg)))
|
||||
|
||||
#?(:clj
|
||||
(defmacro defstate [state & body]
|
||||
(let [[state params] (macro/name-with-attributes state body)
|
||||
|
|
|
|||
18
src/mount/tools/logger.cljc
Normal file
18
src/mount/tools/logger.cljc
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(ns mount.tools.logger
|
||||
#?@(:cljs [(:require [goog.log :as glog])
|
||||
(:import [goog.debug Console])]))
|
||||
|
||||
#?(:cljs
|
||||
(defonce *logger*
|
||||
(do
|
||||
(.setCapturing (Console.) true)
|
||||
(glog/getLogger "mount"))))
|
||||
|
||||
#?(:clj
|
||||
(defn log [msg]
|
||||
(prn msg)))
|
||||
|
||||
#?(:cljs
|
||||
(defn log [msg]
|
||||
(glog/info *logger* msg)))
|
||||
|
||||
Loading…
Reference in a new issue