Skip to content

Commit

Permalink
~wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Oct 2, 2024
1 parent e8c311f commit 15c8836
Showing 1 changed file with 16 additions and 108 deletions.
124 changes: 16 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,75 +45,32 @@ It enables you to write code that is **information-verbose by default**.

## Quick examples

```clojure
(require '[taoensso.telemere :as t])

;; (Just works / no config necessary for typical use cases)

;; Without structured data
(t/log! :info "Hello world!") ; %> Basic log signal (has message)
(t/event! ::my-id :debug) ; %> Basic event signal (just id)

;; With structured data
(t/log! {:level :info, :data {...}} "Hello again!")
(t/event! ::my-id {:level :debug, :data {...}})

;; Trace (can interop with OpenTelemetry)
;; Tracks form runtime, return value, and (nested) parent tree
(t/trace! {:id ::my-id :data {...}}
(do-some-work))

;; Check resulting signal content for debug/tests
(t/with-signal (t/event! ::my-id)) ; => {:keys [ns level id data msg_ ...]}
<details open><summary>Create signals</summary>

;; Getting fancy (all costs are conditional!)
(t/log!
{:level :debug
:sample-rate 0.75 ; 75% sampling (noop 25% of the time)
:when (my-conditional)
:rate-limit {"1 per sec" [1 1000]
"5 per min" [5 60000]}
:rate-limit-by my-user-ip-address ; Optional rate-limit scope

:do (inc-my-metric!)
:let
[diagnostics (my-expensive-diagnostics)
formatted (my-expensive-format diagnostics)]
```clojure
(println "fo)
```
:data
{:diagnostics diagnostics
:formatted formatted
:local-state *my-dynamic-context*}}
</details>
;; Message string or vector to join as string
["Something interesting happened!" formatted])
<details><summary>Filter signals</summary>
;; Set minimum level
(t/set-min-level! :warn) ; For all signals
(t/set-min-level! :log :debug) ; For `log!` signals only
```clojure
(println "foo")
```
;; Set namespace and id filters
(t/set-ns-filter! {:disallow "taoensso.*" :allow "taoensso.sente.*"})
(t/set-id-filter! {:allow #{::my-particular-id "my-app/*"}})
</details>
;; Set minimum level for `event!` signals for particular ns pattern
(t/set-min-level! :event "taoensso.sente.*" :warn)
<details><summary>Adding handlers</summary>
;; Use middleware to:
;; - Transform signals
;; - Filter signals by arb conditions (incl. data/content)
```clojure
(println "foo")
```
(t/set-middleware!
(fn [signal]
(if (-> signal :data :skip-me?)
nil ; Filter signal (don't handle)
(assoc signal :passed-through-middleware? true))))
</details>
(t/with-signal (t/event! ::my-id {:data {:skip-me? true}})) ; => nil
(t/with-signal (t/event! ::my-id {:data {:skip-me? false}})) ; => {...}
;; See `t/help:filters` docstring for more filtering options
```
See [examples.cljc](https://github.com/taoensso/telemere/blob/master/examples.cljc) for REPL-ready snippets!
## Why Telemere?
Expand Down Expand Up @@ -156,55 +113,6 @@ See for intro and basic usage:
<img src="https://img.youtube.com/vi/-L9irDG8ysM/maxresdefault.jpg" alt="Telemere demo video" width="480" border="0" />
</a>
## 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) ; => {<handler-id> {: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. <https://github.com/metosin/jsonista> (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-
Expand Down

0 comments on commit 15c8836

Please sign in to comment.