no start/stop sample logging for started/stopped states
This commit is contained in:
parent
9131cbb17a
commit
78b9a23c71
2 changed files with 29 additions and 31 deletions
|
|
@ -6,30 +6,26 @@
|
||||||
|
|
||||||
(alter-meta! *ns* assoc ::load false)
|
(alter-meta! *ns* assoc ::load false)
|
||||||
|
|
||||||
(defn- f-to-action [f]
|
(defn- f-to-action [f {:keys [status]}]
|
||||||
(let [fname (-> (str f)
|
(let [fname (-> (str f)
|
||||||
(split #"@")
|
(split #"@")
|
||||||
first)]
|
first)]
|
||||||
(case fname
|
(case fname
|
||||||
"mount.core$up" :up
|
"mount.core$up" (when-not (:started status) :up)
|
||||||
"mount.core$down" :down
|
"mount.core$down" (when-not (:stopped status) :down)
|
||||||
"mount.core$sigstop" :suspend
|
|
||||||
"mount.core$sigcont" :resume
|
|
||||||
:noop)))
|
:noop)))
|
||||||
|
|
||||||
(defn whatcha-doing? [{:keys [status suspend]} action]
|
(defn whatcha-doing? [action]
|
||||||
(case action
|
(case action
|
||||||
:up (if (status :suspended) ">> resuming"
|
:up ">> starting"
|
||||||
(if-not (status :started) ">> starting"))
|
:down "<< stopping"
|
||||||
:down (if (or (status :started) (status :suspended)) "<< stopping")
|
false))
|
||||||
:suspend (if (and (status :started) suspend) "<< suspending")
|
|
||||||
:resume (if (status :suspended) ">> resuming")))
|
|
||||||
|
|
||||||
(defn log-status [f & args]
|
(defn log-status [f & args]
|
||||||
(let [{:keys [var] :as state} (second args)
|
(let [[state-name state] args
|
||||||
action (f-to-action f)]
|
action (f-to-action f state)]
|
||||||
(when-let [taking-over-the-world (whatcha-doing? state action)]
|
(when-let [taking-over-the-world (whatcha-doing? action)]
|
||||||
(info (str taking-over-the-world ".. " var)))
|
(info (str taking-over-the-world ".. " state-name)))
|
||||||
(apply f args)))
|
(apply f args)))
|
||||||
|
|
||||||
(defonce lifecycle-fns
|
(defonce lifecycle-fns
|
||||||
|
|
@ -39,6 +35,9 @@
|
||||||
(defn without-logging-status []
|
(defn without-logging-status []
|
||||||
(doall (map #(clear-hooks %) lifecycle-fns)))
|
(doall (map #(clear-hooks %) lifecycle-fns)))
|
||||||
|
|
||||||
|
|
||||||
|
;; this is the one to use:
|
||||||
|
|
||||||
(defn with-logging-status []
|
(defn with-logging-status []
|
||||||
(without-logging-status)
|
(without-logging-status)
|
||||||
(doall (map #(add-hook % log-status) lifecycle-fns)))
|
(doall (map #(add-hook % log-status) lifecycle-fns)))
|
||||||
|
|
|
||||||
|
|
@ -6,30 +6,26 @@
|
||||||
|
|
||||||
(alter-meta! *ns* assoc ::load false)
|
(alter-meta! *ns* assoc ::load false)
|
||||||
|
|
||||||
(defn- f-to-action [f]
|
(defn- f-to-action [f {:keys [status]}]
|
||||||
(let [fname (-> (str f)
|
(let [fname (-> (str f)
|
||||||
(split #"@")
|
(split #"@")
|
||||||
first)]
|
first)]
|
||||||
(case fname
|
(case fname
|
||||||
"mount.core$up" :up
|
"mount.core$up" (when-not (:started status) :up)
|
||||||
"mount.core$down" :down
|
"mount.core$down" (when-not (:stopped status) :down)
|
||||||
"mount.core$sigstop" :suspend
|
|
||||||
"mount.core$sigcont" :resume
|
|
||||||
:noop)))
|
:noop)))
|
||||||
|
|
||||||
(defn whatcha-doing? [{:keys [status suspend]} action]
|
(defn whatcha-doing? [action]
|
||||||
(case action
|
(case action
|
||||||
:up (if (status :suspended) ">> resuming"
|
:up ">> starting"
|
||||||
(if-not (status :started) ">> starting"))
|
:down "<< stopping"
|
||||||
:down (if (or (status :started) (status :suspended)) "<< stopping")
|
false))
|
||||||
:suspend (if (and (status :started) suspend) "<< suspending")
|
|
||||||
:resume (if (status :suspended) ">> resuming")))
|
|
||||||
|
|
||||||
(defn log-status [f & args]
|
(defn log-status [f & args]
|
||||||
(let [{:keys [var] :as state} (second args)
|
(let [[state-name state] args
|
||||||
action (f-to-action f)]
|
action (f-to-action f state)]
|
||||||
(when-let [taking-over-the-world (whatcha-doing? state action)]
|
(when-let [taking-over-the-world (whatcha-doing? action)]
|
||||||
(info (str taking-over-the-world ".. " var)))
|
(info (str taking-over-the-world ".. " state-name)))
|
||||||
(apply f args)))
|
(apply f args)))
|
||||||
|
|
||||||
(defonce lifecycle-fns
|
(defonce lifecycle-fns
|
||||||
|
|
@ -37,7 +33,10 @@
|
||||||
#'mount.core/down})
|
#'mount.core/down})
|
||||||
|
|
||||||
(defn without-logging-status []
|
(defn without-logging-status []
|
||||||
(doall (map clear-hooks lifecycle-fns)))
|
(doall (map #(clear-hooks %) lifecycle-fns)))
|
||||||
|
|
||||||
|
|
||||||
|
;; this is the one to use:
|
||||||
|
|
||||||
(defn with-logging-status []
|
(defn with-logging-status []
|
||||||
(without-logging-status)
|
(without-logging-status)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue