diff --git a/README.md b/README.md index ba90b7b..cf2f4ff 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,10 @@ It enables you to write code that is **information-verbose by default**. ## Quick examples +> (Or see [examples.cljc](https://github.com/taoensso/telemere/blob/master/examples.cljc) for REPL-ready snippets) + +
Create signals
+ ```clojure (require '[taoensso.telemere :as t]) @@ -87,7 +91,13 @@ It enables you to write code that is **information-verbose by default**. ;; Message string or vector to join as string ["Something interesting happened!" formatted]) +``` +
+ +
Filter signals
+ +```clojure ;; Set minimum level (t/set-min-level! :warn) ; For all signals (t/set-min-level! :log :debug) ; For `log!` signals only @@ -115,6 +125,57 @@ It enables you to write code that is **information-verbose by default**. ;; See `t/help:filters` docstring for more filtering options ``` +
+ +
Add handlers
+ +```clojure +;; Add your own signal handler +(t/add-handler! :my-handler + (fn + ([signal] (println signal)) + ([] (println "Handler has shut down")))) + +;; Use `add-handler!` to set handler-level filtering and back-pressure +(t/add-handler! :my-handler + (fn + ([signal] (println signal)) + ([] (println "Handler has shut down"))) + + {:async {:mode :dropping, :buffer-size 1024, :n-threads 1} + :priority 100 + :sample-rate 0.5 + :min-level :info + :ns-filter {:disallow "taoensso.*"} + :rate-limit {"1 per sec" [1 1000]} + ;; See `t/help:handler-dispatch-options` for more + }) + +;; See current handlers +(t/get-handlers) ; => { {:keys [handler-fn handler-stats_ dispatch-opts]}} + +;; Add built-in console handler to print human-readable output +(t/add-handler! :my-handler + (t/handler:console + {:output-fn (t/format-signal-fn {})})) + +;; Add built-in console handler to print edn output +(t/add-handler! :my-handler + (t/handler:console + {:output-fn (t/pr-signal-fn {:pr-fn :edn})})) + +;; Add built-in console handler to print JSON output +;; Ref. (or any alt JSON lib) +#?(:clj (require '[jsonista.core :as jsonista])) +(t/add-handler! :my-handler + (t/handler:console + {:output-fn + #?(:cljs :json ; Use js/JSON.stringify + :clj jsonista/write-value-as-string)})) +``` + +
+ ## Why Telemere? ### Ergonomics @@ -156,55 +217,6 @@ See for intro and basic usage: Telemere demo video -## More examples - -```clojure -;; Add your own signal handler -(t/add-handler! :my-handler - (fn - ([signal] (println signal)) - ([] (println "Shut down handler")))) - -;; Use `add-handler!` to set handler-level filtering and back-pressure -(t/add-handler! :my-handler - (fn - ([signal] (println signal)) - ([] (println "Shut down handler"))) - - {:async {:mode :dropping, :buffer-size 1024, :n-threads 1} - :priority 100 - :sample-rate 0.5 - :min-level :info - :ns-filter {:disallow "taoensso.*"} - :rate-limit {"1 per sec" [1 1000]} - ;; See `t/help:handler-dispatch-options` for more - }) - -;; See current handlers -(t/get-handlers) ; => { {:keys [handler-fn handler-stats_ dispatch-opts]}} - -;; Add built-in console handler to print human-readable output -(t/add-handler! :my-handler - (t/handler:console - {:output-fn (t/format-signal-fn {})})) - -;; Add built-in console handler to print edn output -(t/add-handler! :my-handler - (t/handler:console - {:output-fn (t/pr-signal-fn {:pr-fn :edn})})) - -;; Add built-in console handler to print JSON output -;; Ref. (or any alt JSON lib) -#?(:clj (require '[jsonista.core :as jsonista])) -(t/add-handler! :my-handler - (t/handler:console - {:output-fn - #?(:cljs :json ; Use js/JSON.stringify - :clj jsonista/write-value-as-string)})) -``` - -See [examples.cljc](https://github.com/taoensso/telemere/blob/master/examples.cljc) for REPL-ready snippets! - ## API overview See relevant docstrings (links below) for usage info- diff --git a/examples.cljc b/examples.cljc index c3178a5..33cb5bc 100644 --- a/examples.cljc +++ b/examples.cljc @@ -80,13 +80,13 @@ (t/add-handler! :my-handler (fn ([signal] (println signal)) - ([] (println "Shut down handler")))) + ([] (println "Handler has shut down")))) ;; Use `add-handler!` to set handler-level filtering and back-pressure (t/add-handler! :my-handler (fn ([signal] (println signal)) - ([] (println "Shut down handler"))) + ([] (println "Handler has shut down"))) {:async {:mode :dropping, :buffer-size 1024, :n-threads 1} :priority 100