mirror of https://github.com/status-im/timbre.git
[#133] Faster + more flexible str joins (Clojure 1.7+)
Needs transducers, otherwise falls back to the old method.
This commit is contained in:
parent
aadfd929ee
commit
d913721865
|
@ -5,21 +5,21 @@
|
||||||
(:require
|
(:require
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[io.aviso.exception :as aviso-ex]
|
[io.aviso.exception :as aviso-ex]
|
||||||
[taoensso.encore :as enc :refer (have have? qb)]
|
[taoensso.encore :as enc :refer (compile-if have have? qb)]
|
||||||
[taoensso.timbre.appenders.core :as core-appenders])
|
[taoensso.timbre.appenders.core :as core-appenders])
|
||||||
|
|
||||||
#+cljs
|
#+cljs
|
||||||
(:require
|
(:require
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[taoensso.encore :as enc :refer () :refer-macros (have have?)]
|
[taoensso.encore :as enc :refer () :refer-macros (compile-if have have?)]
|
||||||
[taoensso.timbre.appenders.core :as core-appenders])
|
[taoensso.timbre.appenders.core :as core-appenders])
|
||||||
|
|
||||||
#+cljs
|
#+cljs
|
||||||
(:require-macros [taoensso.timbre :as timbre-macros :refer ()]))
|
(:require-macros [taoensso.timbre :as timbre-macros :refer ()]))
|
||||||
|
|
||||||
(if (vector? taoensso.encore/encore-version)
|
(if (vector? taoensso.encore/encore-version)
|
||||||
(enc/assert-min-encore-version [2 26 0])
|
(enc/assert-min-encore-version [2 29 1])
|
||||||
(enc/assert-min-encore-version 2.26))
|
(enc/assert-min-encore-version 2.29))
|
||||||
|
|
||||||
;;;; Config
|
;;;; Config
|
||||||
|
|
||||||
|
@ -222,6 +222,23 @@
|
||||||
|
|
||||||
;;;; Utils
|
;;;; Utils
|
||||||
|
|
||||||
|
(enc/compile-if (do enc/str-join true) ; Encore v2.29.1+ with transducers
|
||||||
|
(defn- str-join [xs]
|
||||||
|
(enc/str-join " "
|
||||||
|
(map
|
||||||
|
(fn [x]
|
||||||
|
(let [x (enc/nil->str x)] ; Undefined, nil -> "nil"
|
||||||
|
(cond
|
||||||
|
(record? x) (pr-str x)
|
||||||
|
;; (enc/lazy-seq? x) (pr-str x) ; Dubious?
|
||||||
|
:else x))))
|
||||||
|
xs))
|
||||||
|
(defn- str-join [xs] (enc/spaced-str-with-nils xs)))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(defrecord MyRec [x])
|
||||||
|
(str-join ["foo" (MyRec. "foo")]))
|
||||||
|
|
||||||
(defn- ->delay [x] (if (delay? x) x (delay x)))
|
(defn- ->delay [x] (if (delay? x) x (delay x)))
|
||||||
(defn- vsplit-err1 [[v1 :as v]] (if-not (enc/error? v1) [nil v] (enc/vsplit-first v)))
|
(defn- vsplit-err1 [[v1 :as v]] (if-not (enc/error? v1) [nil v] (enc/vsplit-first v)))
|
||||||
(comment
|
(comment
|
||||||
|
@ -337,7 +354,7 @@
|
||||||
(when-not (nil? msg-type)
|
(when-not (nil? msg-type)
|
||||||
(when-let [vargs (have [:or nil? vector?] (force vargs_))]
|
(when-let [vargs (have [:or nil? vector?] (force vargs_))]
|
||||||
(case msg-type
|
(case msg-type
|
||||||
:p (enc/spaced-str vargs)
|
:p (str-join vargs)
|
||||||
:f (let [[fmt args] (enc/vsplit-first vargs)]
|
:f (let [[fmt args] (enc/vsplit-first vargs)]
|
||||||
(enc/format* fmt args))))))
|
(enc/format* fmt args))))))
|
||||||
?data
|
?data
|
||||||
|
@ -581,7 +598,7 @@
|
||||||
|
|
||||||
;;;; Deprecated
|
;;;; Deprecated
|
||||||
|
|
||||||
(defn str-println [& xs] (enc/spaced-str xs))
|
(defn str-println [& xs] (str-join xs))
|
||||||
(defmacro with-log-level [level & body] `(with-level ~level ~@body))
|
(defmacro with-log-level [level & body] `(with-level ~level ~@body))
|
||||||
(defmacro with-logging-config [config & body] `(with-config ~config ~@body))
|
(defmacro with-logging-config [config & body] `(with-config ~config ~@body))
|
||||||
(defn logging-enabled? [level compile-time-ns] (log? level (str compile-time-ns)))
|
(defn logging-enabled? [level compile-time-ns] (log? level (str compile-time-ns)))
|
||||||
|
|
Loading…
Reference in New Issue