mirror of
https://github.com/status-im/re-frame.git
synced 2025-02-23 23:38:11 +00:00
Breaking change to logging
This commit is contained in:
parent
da9c11eae0
commit
053771ad9d
23
CHANGES.md
23
CHANGES.md
@ -23,8 +23,27 @@ Headline:
|
|||||||
|
|
||||||
|
|
||||||
Breaking:
|
Breaking:
|
||||||
- requires Reagent >= 0.6.0 or later. It won't work with <= Reagent 0.5.2.
|
- requires Reagent >= 0.6.0 or later. It won't work with <= Reagent 0.5.2.
|
||||||
- XXX undo extracted and put into sister library
|
|
||||||
|
- By default, re-frame uses `js/console` functions like `error` and `warn` when logging, but you can
|
||||||
|
supply alternatives via `re-frame.core/set-loggers!`.
|
||||||
|
|
||||||
|
With this release, alternatives you supply will be called with different parameter values.
|
||||||
|
Previously loggers were given a single `str` parameter but now they are expected to act
|
||||||
|
like `console.log` itself and take variadic, non string params. Sorry to break things, but
|
||||||
|
we are trying to maximise use of cljs-devtools and information is lost when strings are
|
||||||
|
output, instead of real data.
|
||||||
|
|
||||||
|
To transition, here's the tweak you can make:
|
||||||
|
```
|
||||||
|
;; your old version might have looked like this. Single string parameter.
|
||||||
|
(defn my-logger [s] (do-something-with s))
|
||||||
|
|
||||||
|
;; your new version will have variadic params, and turn them into a string
|
||||||
|
(defn myloggerr [& args] (do-something-with (apply str args))
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
- XXXX middleware for spec checking of event vectors
|
- XXXX middleware for spec checking of event vectors
|
||||||
|
@ -1,25 +1,28 @@
|
|||||||
(ns re-frame.utils
|
(ns re-frame.utils
|
||||||
(:require
|
(:require
|
||||||
[clojure.set :refer [difference]]))
|
[clojure.set :refer [difference]]))
|
||||||
|
|
||||||
|
|
||||||
;; -- Logging -----------------------------------------------------------------
|
;; -- Logging -----------------------------------------------------------------
|
||||||
;;
|
;;
|
||||||
;; re-frame internally uses a set of logging functions which, by default,
|
;; re-frame uses a set of logging functions which are, by default, those from
|
||||||
;; print to js/console.
|
;; js/console.
|
||||||
;; Use set-loggers! if you want to change this default behaviour.
|
;; Use set-loggers! if you want to change this default behaviour.
|
||||||
;; In production environment, you may want to capture exceptions and POST
|
|
||||||
;; them somewhere. to , you might want to override the way that exceptions are
|
|
||||||
;; handled by overridding "error"
|
|
||||||
;;
|
;;
|
||||||
(def default-loggers
|
(def default-log (js/console.log.bind js/console))
|
||||||
{:log #(.log js/console %)
|
(def default-warn (js/console.warn.bind js/console))
|
||||||
:warn #(.warn js/console %)
|
(def default-error (js/console.error.bind js/console))
|
||||||
:error #(.error js/console %)
|
(def default-group (if (.-group js/console) (js/console.group.bind js/console) default-log)) ;; group does not exist < IE 11
|
||||||
:group #(if (.-groupCollapsed js/console) (.groupCollapsed js/console %) (.log js/console %)) ;; group does not exist < IE 11
|
(def default-groupEnd (if (.-groupEnd js/console) (js/console.groupEnd.bind js/console) #())) ;; groupEnd does not exist < IE 11
|
||||||
:groupEnd #(when (.-groupEnd js/console) (.groupEnd js/console))}) ;; groupEnd does not exist < IE 11
|
|
||||||
|
|
||||||
;; holds the current set of loggers.
|
(def default-loggers
|
||||||
|
{:log #(apply default-log %)
|
||||||
|
:warn #(apply default-warn %)
|
||||||
|
:error #(apply default-error %)
|
||||||
|
:group #(apply default-group %)
|
||||||
|
:groupEnd #(apply default-groupEnd %)})
|
||||||
|
|
||||||
|
;; holds the current set of loggin functions.
|
||||||
(def loggers (atom default-loggers))
|
(def loggers (atom default-loggers))
|
||||||
|
|
||||||
(defn set-loggers!
|
(defn set-loggers!
|
||||||
@ -30,11 +33,11 @@
|
|||||||
(swap! loggers merge new-loggers))
|
(swap! loggers merge new-loggers))
|
||||||
|
|
||||||
|
|
||||||
(defn log [& args] ((:log @loggers) (apply str args)))
|
(defn log [& args] ((:log @loggers) args))
|
||||||
(defn warn [& args] ((:warn @loggers) (apply str args)))
|
(defn warn [& args] ((:warn @loggers) args))
|
||||||
(defn group [& args] ((:group @loggers) (apply str args)))
|
(defn group [& args] ((:group @loggers) args))
|
||||||
(defn groupEnd [& args] ((:groupEnd @loggers) (apply str args)))
|
(defn groupEnd [& args] ((:groupEnd @loggers) args))
|
||||||
(defn error [& args] ((:error @loggers) (apply str args)))
|
(defn error [& args] ((:error @loggers) args))
|
||||||
|
|
||||||
;; -- Misc --------------------------------------------------------------------
|
;; -- Misc --------------------------------------------------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user