CLJC: tools.logging as default re-frame.loggers

This commit is contained in:
Sam Roberton 2016-07-21 17:08:38 +10:00
parent b4d915c395
commit ef3656ff60
2 changed files with 19 additions and 11 deletions

View File

@ -8,7 +8,8 @@
:profiles {:debug {:debug true}
:dev {:dependencies [[karma-reporter "0.3.0"]
[binaryage/devtools "0.7.2"]]
[binaryage/devtools "0.7.2"]
[org.clojure/tools.logging "0.3.1"]]
:plugins [[lein-cljsbuild "1.1.3"]
[lein-npm "0.6.2"]
[lein-figwheel "0.5.4-7"]

View File

@ -1,6 +1,13 @@
(ns re-frame.loggers
(:require
[clojure.set :refer [difference]]))
[clojure.set :refer [difference]]
#?@(:clj [[clojure.string :as str]
[clojure.tools.logging :as log]])))
(defn log [level & args]
(log/log level (if (= 1 (count args))
(first args)
(str/join " " (map pr-str args)))))
;; "loggers" holds the current set of logging functions.
;; By default, re-frame uses the functions provided by js/console.
@ -8,15 +15,15 @@
(def ^:private loggers
(atom {:log #?(:cljs (js/console.log.bind js/console)
:clj println)
:clj (partial log :info))
:warn #?(:cljs (js/console.warn.bind js/console)
:clj (partial println "WARN: "))
:clj (partial log :warn))
:error #?(:cljs (js/console.error.bind js/console)
:clj (partial println "ERROR: "))
:clj (partial log :error))
:group #?(:cljs (if (.-group js/console) ;; console.group does not exist < IE 11
(js/console.group.bind js/console)
(js/console.log.bind js/console))
:clj println)
:clj (partial log :info))
:groupEnd #?(:cljs (if (.-groupEnd js/console) ;; console.groupEnd does not exist < IE 11
(js/console.groupEnd.bind js/console)
#())