Skip to content

Commit

Permalink
[mod] [#39] Remove shell API
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Dec 22, 2024
1 parent 706a8b6 commit 096c432
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 297 deletions.
1 change: 0 additions & 1 deletion projects/main/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
[org.clojure/test.check "1.1.1"]
[org.clojure/tools.logging "1.3.0"]
[org.slf4j/slf4j-api "2.0.16"]
[com.taoensso/telemere-shell "1.0.0-RC1"]
[com.taoensso/telemere-slf4j "1.0.0-RC1"]
#_[org.slf4j/slf4j-simple "2.0.16"]
#_[org.slf4j/slf4j-nop "2.0.16"]
Expand Down
2 changes: 1 addition & 1 deletion projects/main/src/taoensso/telemere/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@
:arglists (signal-arglists :signal!)}

;; TODO Maybe later, once we're sure we don't want additional arities?
;; Remember to also update signal-arglists, shell, etc.
;; Remember to also update signal-arglists, etc.
;; ([arg1 & more] (enc/keep-callsite `(signal! ~(apply hash-map arg1 more))))
([opts]
(have? map? opts) ; We require const map keys, but vals may require eval
Expand Down
8 changes: 1 addition & 7 deletions projects/main/test/taoensso/telemere_tests.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
:refer [signal! with-signal with-signals]
:rename {signal! sig!, with-signal with-sig, with-signals with-sigs}]

[taoensso.telemere.shell :as shell]
[taoensso.telemere.utils :as utils]
[taoensso.telemere.timbre :as timbre]
#_[taoensso.telemere.tools-logging :as tools-logging]
Expand Down Expand Up @@ -286,12 +285,7 @@
(update-in [:inst] enc/inst->udt)
(update-in [:end-inst] enc/inst->udt))]

[(is (= sv1 (read-string (pr-str sv1))))])))

(testing "Shell API"
[(is (sm? (with-sig (shell/signal! {:level :info})) {:level :info, :ns "taoensso.telemere-tests", :line :submap/some}))
(is (true? (tel/with-min-level :debug (shell/signal-allowed? {:level :debug}))))
(is (false? (tel/with-min-level :debug (shell/signal-allowed? {:level :trace}))))])])
[(is (= sv1 (read-string (pr-str sv1))))])))])

(deftest _handlers
;; Basic handler tests are in Encore
Expand Down
15 changes: 0 additions & 15 deletions projects/shell/.gitignore

This file was deleted.

44 changes: 0 additions & 44 deletions projects/shell/project.clj

This file was deleted.

183 changes: 0 additions & 183 deletions projects/shell/src/taoensso/telemere/shell.cljc

This file was deleted.

49 changes: 3 additions & 46 deletions wiki/9-Authors.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Are you a library author/maintainer that's considering **using Telemere in your library**?

You have **two options** below-

# Options
## 1. Common logging facade (basic logging only)

Expand Down Expand Up @@ -31,49 +33,4 @@ The most common thing users may want to do is **adjust the minimum level** of si
(defonce ^:private __set-default-log-level (set-min-log-level! :warn))
```

This way your users can easily disable, decrease, or increase signal output from your library without even needing to touch Telemere or to be aware of its existence.

## 3. Telemere as an optional dependency

Include the (super lightweight) [Telemere shell API](https://clojars.org/com.taoensso/telemere-shell) in your **library's dependencies**.

Your library will then be able to emit structured logs/telemetry **when Telemere is present**, or fall back to something like [tools.logging](https://github.com/clojure/tools.logging) otherwise.

The main trade-off is that your signal calls will be more verbose:

```clojure
(ns my-lib
(:require
[taoensso.telemere.shell :as t] ; `com.taoensso/telemere-shell` dependency
[clojure.tools.logging :as ctl] ; `org.clojure/tools.logging` dependency
))

(t/require-telemere-if-present) ; Just below `ns` form

;; Optional convenience for library users
(defn set-min-level!
"If it's present, sets Telemere's minimum level for <my-lib> namespaces.
This will affect all signals (logs) created by <my-lib>.
Possible minimum levels (from most->least verbose):
#{:trace :debug :info :warn :error :fatal :report}.
The default minimum level is `:warn`."
[min-level]
(t/if-telemere
(do (t/set-min-level! nil \"my-lib(.*)\" min-level) true)
false))

(defonce ^:private __set-default-min-level (set-min-level! :warn))

;; Creates Telemere signal if Telemere is present,
;; otherwise logs with tools.logging
(signal!
{:kind :log, :id :my-id, :level :warn,
:let [x :x]
:msg [\"Hello\" \"world\" x]
:data {:a :A :x x}
:fallback (ctl/warn (str \"Hello world\" x))})
```

See [here](https://cljdoc.org/d/com.taoensso/telemere-shell/CURRENT/api/taoensso.telemere.shell) for more info.
This way your users can easily disable, decrease, or increase signal output from your library without even needing to touch Telemere or to be aware of its existence.

0 comments on commit 096c432

Please sign in to comment.