mirror of
https://github.com/taoensso/telemere.git
synced 2026-02-11 14:05:16 +00:00
[nop] Restructure handlers
This commit is contained in:
parent
99b2e0c0cb
commit
323ba0e99c
4 changed files with 51 additions and 58 deletions
|
|
@ -7,12 +7,13 @@
|
||||||
{:author "Peter Taoussanis (@ptaoussanis)"}
|
{:author "Peter Taoussanis (@ptaoussanis)"}
|
||||||
(:refer-clojure :exclude [binding newline])
|
(:refer-clojure :exclude [binding newline])
|
||||||
(:require
|
(:require
|
||||||
[taoensso.encore :as enc :refer [binding have have?]]
|
[taoensso.encore :as enc :refer [binding have have?]]
|
||||||
[taoensso.encore.signals :as sigs]
|
[taoensso.encore.signals :as sigs]
|
||||||
[taoensso.telemere.impl :as impl]
|
[taoensso.telemere.impl :as impl]
|
||||||
[taoensso.telemere.utils :as utils]
|
[taoensso.telemere.utils :as utils]
|
||||||
[taoensso.telemere.handlers :as handlers]
|
[taoensso.telemere.console-handlers :as console-handlers]
|
||||||
#?(:clj [taoensso.telemere.streams :as streams]))
|
#?(:clj [taoensso.telemere.file-handler :as file-handler])
|
||||||
|
#?(:clj [taoensso.telemere.streams :as streams]))
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(:require-macros
|
(:require-macros
|
||||||
|
|
@ -369,15 +370,23 @@
|
||||||
|
|
||||||
;;;; Handlers
|
;;;; Handlers
|
||||||
|
|
||||||
|
(enc/def* help:signal-formatters
|
||||||
|
"Common signal formatters include:
|
||||||
|
(utils/format-signal-str->fn) {<opts>}) ; For human-readable string output (default)
|
||||||
|
(utils/format-signal->edn-fn) {<opts>}) ; For edn output
|
||||||
|
(utils/format-signal->json-fn {<opts>}) ; For JSON output
|
||||||
|
|
||||||
|
See relevant docstrings for details."
|
||||||
|
"See docstring")
|
||||||
|
|
||||||
(enc/defaliases
|
(enc/defaliases
|
||||||
#?(:default handlers/console-handler)
|
#?(:default console-handlers/handler:console)
|
||||||
#?(:cljs handlers/raw-console-handler)
|
#?(:cljs console-handlers/handler:console-raw)
|
||||||
#?(:clj handlers/file-handler))
|
#?(:clj file-handler/handler:file))
|
||||||
|
|
||||||
(defonce ^:no-doc __add-default-handlers
|
(defonce ^:no-doc __add-default-handlers
|
||||||
(do
|
(do
|
||||||
(add-handler! :default-console-handler
|
(add-handler! :default/console (handler:console))
|
||||||
(console-handler))
|
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
;;;; Flow benchmarks
|
;;;; Flow benchmarks
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,15 @@
|
||||||
(ns taoensso.telemere.handlers
|
(ns ^:no-doc taoensso.telemere.console-handlers
|
||||||
"Built-in Telemere handlers."
|
"Private ns, implementation detail."
|
||||||
(:require
|
(:require
|
||||||
[taoensso.encore :as enc :refer [have have?]]
|
[taoensso.encore :as enc :refer [have have?]]
|
||||||
[taoensso.telemere.utils :as utils]
|
[taoensso.telemere.utils :as utils]))
|
||||||
#?(:clj [taoensso.telemere.handlers.file-handler :as file-handler])))
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(require '[taoensso.telemere :as tel])
|
(remove-ns 'taoensso.telemere.console-handlers)
|
||||||
(remove-ns 'taoensso.telemere.handlers)
|
|
||||||
(:api (enc/interns-overview)))
|
(:api (enc/interns-overview)))
|
||||||
|
|
||||||
;;;; Console handlers
|
|
||||||
|
|
||||||
(enc/def* help:signal-formatters
|
|
||||||
"Common signal formatters include:
|
|
||||||
(utils/format-signal-str->fn) {<opts>}) ; For human-readable string output (default)
|
|
||||||
(utils/format-signal->edn-fn) {<opts>}) ; For edn output
|
|
||||||
(utils/format-signal->json-fn {<opts>}) ; For JSON output
|
|
||||||
|
|
||||||
See relevant docstrings for details."
|
|
||||||
"See docstring")
|
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defn console-handler
|
(defn ^:public handler:console
|
||||||
"Experimental, subject to change.
|
"Experimental, subject to change.
|
||||||
|
|
||||||
Returns a (fn handler [signal]) that:
|
Returns a (fn handler [signal]) that:
|
||||||
|
|
@ -35,7 +22,7 @@
|
||||||
`:stream` - `java.io.writer`
|
`:stream` - `java.io.writer`
|
||||||
Defaults to `*err*` if `utils/error-signal?` is true, and `*out*` otherwise."
|
Defaults to `*err*` if `utils/error-signal?` is true, and `*out*` otherwise."
|
||||||
|
|
||||||
([] (console-handler nil))
|
([] (handler:console nil))
|
||||||
([{:keys [format-signal-fn stream]
|
([{:keys [format-signal-fn stream]
|
||||||
:or {format-signal-fn (utils/format-signal->str-fn)}}]
|
:or {format-signal-fn (utils/format-signal->str-fn)}}]
|
||||||
|
|
||||||
|
|
@ -43,7 +30,7 @@
|
||||||
error-signal? utils/error-signal?
|
error-signal? utils/error-signal?
|
||||||
nl utils/newline]
|
nl utils/newline]
|
||||||
|
|
||||||
(fn a-console-handler
|
(fn a-handler:console
|
||||||
([]) ; Shut down (no-op)
|
([]) ; Shut down (no-op)
|
||||||
([signal]
|
([signal]
|
||||||
(let [^java.io.Writer stream
|
(let [^java.io.Writer stream
|
||||||
|
|
@ -53,7 +40,7 @@
|
||||||
(.flush stream))))))))
|
(.flush stream))))))))
|
||||||
|
|
||||||
:cljs
|
:cljs
|
||||||
(defn console-handler
|
(defn ^:public handler:console
|
||||||
"Experimental, subject to change.
|
"Experimental, subject to change.
|
||||||
|
|
||||||
If `js/console` exists, returns a (fn handler [signal]) that:
|
If `js/console` exists, returns a (fn handler [signal]) that:
|
||||||
|
|
@ -63,7 +50,7 @@
|
||||||
Options:
|
Options:
|
||||||
`:format-signal-fn` - (fn [signal]) => output, see `help:signal-formatters`"
|
`:format-signal-fn` - (fn [signal]) => output, see `help:signal-formatters`"
|
||||||
|
|
||||||
([] (console-handler nil))
|
([] (handler:console nil))
|
||||||
([{:keys [format-signal-fn]
|
([{:keys [format-signal-fn]
|
||||||
:or {format-signal-fn (utils/format-signal->str-fn)}}]
|
:or {format-signal-fn (utils/format-signal->str-fn)}}]
|
||||||
|
|
||||||
|
|
@ -71,7 +58,7 @@
|
||||||
(let [js-console-logger utils/js-console-logger
|
(let [js-console-logger utils/js-console-logger
|
||||||
nl utils/newline]
|
nl utils/newline]
|
||||||
|
|
||||||
(fn a-console-handler
|
(fn a-handler:console
|
||||||
([]) ; Shut down (no-op)
|
([]) ; Shut down (no-op)
|
||||||
([signal]
|
([signal]
|
||||||
(when-let [output (format-signal-fn signal)]
|
(when-let [output (format-signal-fn signal)]
|
||||||
|
|
@ -88,7 +75,7 @@
|
||||||
([x1 x2 x3 & more] (apply logger x1 x2 x3 more)))))
|
([x1 x2 x3 & more] (apply logger x1 x2 x3 more)))))
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(defn raw-console-handler
|
(defn ^:public handler:console-raw
|
||||||
"Experimental, subject to change.
|
"Experimental, subject to change.
|
||||||
|
|
||||||
If `js/console` exists, returns a (fn handler [signal]) that:
|
If `js/console` exists, returns a (fn handler [signal]) that:
|
||||||
|
|
@ -98,7 +85,7 @@
|
||||||
Intended for use with browser formatting tools like `binaryage/devtools`,
|
Intended for use with browser formatting tools like `binaryage/devtools`,
|
||||||
Ref. <https://github.com/binaryage/cljs-devtools>."
|
Ref. <https://github.com/binaryage/cljs-devtools>."
|
||||||
|
|
||||||
([] (raw-console-handler nil))
|
([] (handler:console-raw nil))
|
||||||
([{:keys [format-signal-prelude-fn format-nsecs-fn] :as opts
|
([{:keys [format-signal-prelude-fn format-nsecs-fn] :as opts
|
||||||
:or
|
:or
|
||||||
{format-signal-prelude-fn (utils/format-signal-prelude-fn) ; (fn [signal])
|
{format-signal-prelude-fn (utils/format-signal-prelude-fn) ; (fn [signal])
|
||||||
|
|
@ -113,7 +100,7 @@
|
||||||
:format-error-fn nil
|
:format-error-fn nil
|
||||||
:raw-error? true})]
|
:raw-error? true})]
|
||||||
|
|
||||||
(fn a-raw-console-handler
|
(fn a-handler:console-raw
|
||||||
([]) ; Shut down (no-op)
|
([]) ; Shut down (no-op)
|
||||||
([signal]
|
([signal]
|
||||||
(let [{:keys [level error]} signal
|
(let [{:keys [level error]} signal
|
||||||
|
|
@ -127,7 +114,3 @@
|
||||||
(.call logger logger stack))
|
(.call logger logger stack))
|
||||||
|
|
||||||
(.groupEnd js/console)))))))))
|
(.groupEnd js/console)))))))))
|
||||||
|
|
||||||
;;;; File handler
|
|
||||||
|
|
||||||
#?(:clj (enc/defalias file-handler/file-handler))
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
(ns ^:no-doc taoensso.telemere.handlers.file-handler
|
(ns ^:no-doc taoensso.telemere.file-handler
|
||||||
"Private ns, implementation detail."
|
"Private ns, implementation detail."
|
||||||
(:require
|
(:require
|
||||||
[taoensso.encore :as enc :refer [have have?]]
|
[taoensso.encore :as enc :refer [have have?]]
|
||||||
[taoensso.telemere.utils :as utils]))
|
[taoensso.telemere.utils :as utils]))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(remove-ns 'taoensso.telemere.handlers.file-handler)
|
(remove-ns 'taoensso.telemere.file-handler)
|
||||||
(:api (enc/interns-overview)))
|
(:api (enc/interns-overview)))
|
||||||
|
|
||||||
;;;; Implementation
|
;;;; Implementation
|
||||||
|
|
@ -263,7 +263,7 @@
|
||||||
|
|
||||||
;;;; Handler
|
;;;; Handler
|
||||||
|
|
||||||
(defn ^:public file-handler
|
(defn ^:public handler:file
|
||||||
"Experimental, subject to change.
|
"Experimental, subject to change.
|
||||||
|
|
||||||
Returns a (fn handler [signal]) that:
|
Returns a (fn handler [signal]) that:
|
||||||
|
|
@ -296,7 +296,7 @@
|
||||||
`:max-num-intervals` ∈ #{nil <pos-int>} (default 6)
|
`:max-num-intervals` ∈ #{nil <pos-int>} (default 6)
|
||||||
Maximum number of intervals (days/weeks/months) to retain."
|
Maximum number of intervals (days/weeks/months) to retain."
|
||||||
|
|
||||||
([] (file-handler nil))
|
([] (handler:file nil))
|
||||||
([{:keys
|
([{:keys
|
||||||
[format-signal-fn
|
[format-signal-fn
|
||||||
path interval
|
path interval
|
||||||
|
|
@ -357,7 +357,7 @@
|
||||||
|
|
||||||
lock (Object.)]
|
lock (Object.)]
|
||||||
|
|
||||||
(fn a-file-handler
|
(fn a-handler:file
|
||||||
([] (locking lock (fw))) ; Close writer
|
([] (locking lock (fw))) ; Close writer
|
||||||
([signal]
|
([signal]
|
||||||
(when-let [output (format-signal-fn signal)]
|
(when-let [output (format-signal-fn signal)]
|
||||||
|
|
@ -392,10 +392,10 @@
|
||||||
(.setLastModified (utils/as-file "test/logs/app6.log")
|
(.setLastModified (utils/as-file "test/logs/app6.log")
|
||||||
(enc/as-udt "1999-01-01T01:00:00.00Z"))
|
(enc/as-udt "1999-01-01T01:00:00.00Z"))
|
||||||
|
|
||||||
(let [hf
|
(let [hfn
|
||||||
(file-handler
|
(handler:file
|
||||||
{:path "test/logs/app6.log"
|
{:path "test/logs/app6.log"
|
||||||
:max-num-intervals 2
|
:max-num-intervals 2
|
||||||
:max-num-parts 2})]
|
:max-num-parts 2})]
|
||||||
|
|
||||||
(hf {:info :level :msg_ "hello"}) (hf)))
|
(hfn {:info :level :msg_ "hello"}) (hfn)))
|
||||||
|
|
@ -8,12 +8,13 @@
|
||||||
:refer [signal! with-signal with-signals]
|
:refer [signal! with-signal with-signals]
|
||||||
:rename {signal! sig!, with-signal with-sig, with-signals with-sigs}]
|
:rename {signal! sig!, with-signal with-sig, with-signals with-sigs}]
|
||||||
|
|
||||||
[taoensso.telemere.utils :as utils]
|
[taoensso.telemere.utils :as utils]
|
||||||
[taoensso.telemere.timbre-shim :as timbre]
|
[taoensso.telemere.timbre-shim :as timbre]
|
||||||
[taoensso.telemere.handlers :as handlers]
|
|
||||||
#?(:clj [taoensso.telemere.handlers.file-handler :as fh])
|
|
||||||
#?(:clj [taoensso.telemere.slf4j :as slf4j])
|
#?(:clj [taoensso.telemere.slf4j :as slf4j])
|
||||||
#?(:clj [clojure.tools.logging :as ctl])))
|
#?(:clj [clojure.tools.logging :as ctl])
|
||||||
|
|
||||||
|
#?(:default [taoensso.telemere.console-handlers :as ch])
|
||||||
|
#?(:clj [taoensso.telemere.file-handler :as fh])))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(remove-ns 'taoensso.telemere-tests)
|
(remove-ns 'taoensso.telemere-tests)
|
||||||
|
|
@ -38,7 +39,7 @@
|
||||||
(def pstr? (enc/pred string?))
|
(def pstr? (enc/pred string?))
|
||||||
(def pnat-int? (enc/pred enc/nat-int?)))
|
(def pnat-int? (enc/pred enc/nat-int?)))
|
||||||
|
|
||||||
;; (tel/remove-handler! :default-console-handler)
|
;; (tel/remove-handler! :default/console)
|
||||||
(let [sig-handlers_ (atom nil)]
|
(let [sig-handlers_ (atom nil)]
|
||||||
(test/use-fixtures :once
|
(test/use-fixtures :once
|
||||||
(enc/test-fixtures
|
(enc/test-fixtures
|
||||||
|
|
@ -790,9 +791,9 @@
|
||||||
|
|
||||||
(deftest _other-handlers
|
(deftest _other-handlers
|
||||||
;; For now just testing that basic construction succeeds
|
;; For now just testing that basic construction succeeds
|
||||||
[#?(:default (is (fn? (handlers/console-handler))))
|
[#?(:default (is (fn? (ch/handler:console))))
|
||||||
#?(:cljs (is (fn? (handlers/raw-console-handler))))
|
#?(:cljs (is (fn? (ch/handler:console-raw))))
|
||||||
#?(:clj (is (fn? (handlers/file-handler))))])
|
#?(:clj (is (fn? (fh/handler:file))))])
|
||||||
|
|
||||||
;;;;
|
;;;;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue