Compare commits

..

17 commits

Author SHA1 Message Date
Peter Taoussanis
798e0fddc4 v1.2.1 (2025-12-16)
Some checks failed
Clj tests / tests (17, ubuntu-latest) (push) Has been cancelled
Clj tests / tests (19, ubuntu-latest) (push) Has been cancelled
Clj tests / tests (21, ubuntu-latest) (push) Has been cancelled
Cljs tests / tests (21, ubuntu-latest) (push) Has been cancelled
Graal tests / tests (17, macOS-latest) (push) Has been cancelled
Graal tests / tests (17, ubuntu-latest) (push) Has been cancelled
Graal tests / tests (17, windows-latest) (push) Has been cancelled
2025-12-16 10:16:51 +01:00
Peter Taoussanis
6030c472ae [fix] Timbre->Telemere appender: missing error regression
Recent 47af80319d (in Telemere v1.2.0)
accidentally removed errors from Timbre->Telemere signals.
2025-12-16 10:12:23 +01:00
Peter Taoussanis
1d6bdaf7e5 [doc] Housekeeping
Some checks failed
Clj tests / tests (17, ubuntu-latest) (push) Has been cancelled
Clj tests / tests (19, ubuntu-latest) (push) Has been cancelled
Clj tests / tests (21, ubuntu-latest) (push) Has been cancelled
Cljs tests / tests (21, ubuntu-latest) (push) Has been cancelled
Graal tests / tests (17, macOS-latest) (push) Has been cancelled
Graal tests / tests (17, ubuntu-latest) (push) Has been cancelled
Graal tests / tests (17, windows-latest) (push) Has been cancelled
2025-12-12 12:13:59 +01:00
Peter Taoussanis
6cc54527f2 v1.2.0 (2025-12-09)
Some checks are pending
Clj tests / tests (17, ubuntu-latest) (push) Waiting to run
Clj tests / tests (19, ubuntu-latest) (push) Waiting to run
Clj tests / tests (21, ubuntu-latest) (push) Waiting to run
Cljs tests / tests (21, ubuntu-latest) (push) Waiting to run
Graal tests / tests (17, macOS-latest) (push) Waiting to run
Graal tests / tests (17, ubuntu-latest) (push) Waiting to run
Graal tests / tests (17, windows-latest) (push) Waiting to run
2025-12-09 17:55:48 +01:00
Peter Taoussanis
56e35f3f58 [nop] Bump deps
Some checks are pending
Clj tests / tests (17, ubuntu-latest) (push) Waiting to run
Clj tests / tests (19, ubuntu-latest) (push) Waiting to run
Clj tests / tests (21, ubuntu-latest) (push) Waiting to run
Cljs tests / tests (21, ubuntu-latest) (push) Waiting to run
Graal tests / tests (17, macOS-latest) (push) Waiting to run
Graal tests / tests (17, ubuntu-latest) (push) Waiting to run
Graal tests / tests (17, windows-latest) (push) Waiting to run
2025-12-09 13:10:11 +01:00
Peter Taoussanis
a6fc4adf6a [new] OpenTelemetry handler: support spans created outside Telemere
Some checks failed
Clj tests / tests (17, ubuntu-latest) (push) Has been cancelled
Clj tests / tests (19, ubuntu-latest) (push) Has been cancelled
Clj tests / tests (21, ubuntu-latest) (push) Has been cancelled
Cljs tests / tests (21, ubuntu-latest) (push) Has been cancelled
Graal tests / tests (17, macOS-latest) (push) Has been cancelled
Graal tests / tests (17, ubuntu-latest) (push) Has been cancelled
Graal tests / tests (17, windows-latest) (push) Has been cancelled
BEFORE this commit:

  Telemere captured OpenTelemetry context only when generating
  tracing signals (`trace!`, `spy!`, etc.).

AFTER this commit:

  Telemere always captures OpenTelemetry context when present.

Motivation for the change:

  Telemere users may have spans automatically created by the
  OpenTelemetry Java Agent, or manually created by other libs
  like clj-otel.

  By always capturing the OpenTelemetry context when present,
  this lets even non-tracing Telemere signals (like `log!`)
  include the relevant trace and span IDs for external tooling.

Thanks to @devurandom for suggesting this, and for helping
debug/identify the necessary changes 🙏
2025-12-05 08:03:41 +01:00
Peter Taoussanis
6155713fde [fix] OpenTelemetry handler: add missing line info to output
Previous code was a vestigial leftover from when signals
had {:line <num> :column <num> ...} rather than
{:coords [<line-num> <column-num>] ...}
2025-12-04 21:13:41 +01:00
Peter Taoussanis
a883df3c41 [new] [#68] Add config to skip host and/or thread info 2025-12-04 21:13:41 +01:00
Peter Taoussanis
e6ce33dd4e [mod] SLF4J->Telemere backend: move noisy stuff out of signal data
This is a BREAKING change for the small minority of users that:

  1. Are using the `taoensso.telemere.slf4j` backend, AND
  2. Are using the low-level `:slf4j/args` or `:slf4j/marker-names`
     values in signal `:data`

BEFORE this commit:

  SLF4J signals contain:
  {:data {:slf4j/kvs {...},
          :slf4j/args [...],
          :slf4j/marker-names #{...}},
   ...}.

AFTER this commit:

  SLF4J signals contain:
  {:data {:slf4j/kvs {...}},
   :kvs  {:slf4j/args <Object[]>,
          :slf4j/markers #{...}},
   ...}

  So:
    - [:data :slf4j/marker-names] has moved to [:kvs :slf4j/markers].
    - [:data :slf4j/args]         has moved to [:kvs :slf4j/args],
      and is now an Object[] rather than vector.

Motivation for the change:

  The new behaviour is a more sensible default.

  Basically: anything in `:data` is included by default in output.
  But :slf4j/args are generally anyway already in the signal's formatted
  message, so this ends up just creating duplicate output.

  Likewise markers are generally used more for filtering/xfns than for
  output labelling, so excluding them from default output is sensible.
2025-12-04 21:13:37 +01:00
Peter Taoussanis
cc680b06f5 [mod] Timbre shim API: move noisy :vargs out of signal data
This is a BREAKING change but only relevant for a TINY minority
of users that:

  1. Are using the `taoensso.telemere.timbre` API shim, AND
  2. Are using the low-level `:vargs` value in signal `:data`

BEFORE this commit:

  The taoensso.telemere.timbre shim API produces signals with
  {:data {:vargs [...]}, ...} with `:vargs` a vector of raw args
  provided by Timbre.

AFTER this commit:

  The taoensso.telemere.timbre shim API produces signals with
  {:kvs {:timbre/vargs [...]}, ...} with `:vargs` a vector of raw
  args provided by Timbre.

  I.e. [:data :vargs] has been moved to [:kvs :timbre/vargs].

Motivation for the change:

  The new behaviour is a more sensible default.

  Basically: anything in `:data` is included by default in output.
  But vargs are generally anyway already in the signal's formatted
  message, so this ends up just creating duplicate output.
2025-12-04 11:24:55 +01:00
Peter Taoussanis
47af80319d [mod] [fix] Timbre->Telemere appender: de-duplicate output formatting
BEFORE this commit:

  The Timbre->Telemere appender produced duplicate preamble output
  (timestamp, namespace, etc.). Both Timbre AND Telemere were adding
  preamble info.

AFTER this commit:

  Now ONLY Telemere adds preamble info.
  Timbre's `:output-fn` is ignored.
2025-12-04 11:22:52 +01:00
Peter Taoussanis
b56e1c4529 [mod] [fix] Timbre->Telemere appender: fix callsite coords
There was unfortunately a bug in the Timbre->Telemere appender that
was producing signals with {:line <num> :column <num> ...} keys instead
of the expected {:coords [<line-num> <column-num>] ...} key.

This commit fixes the mistake, which should help fix issues with
any downstream middleware or handlers that expect a `:coords` key.

Unfortunately this fix could break a small minority of users that
have come to expect `:line` and `:column` keys on their Timbre signals
(none of the built-in middleware or handlers do).

Apologies for the trouble!
2025-12-04 11:22:52 +01:00
Peter Taoussanis
8a3ae14f45 [fix] Correctly handle nil :run opt
Before commit: {:run nil} didn't    register  as a tracing signal
After  commit: {:run nil} correctly registers as a tracing signal with `nil` form

nil forms aren't typically useful or used, but can come up by accident
so it's important to handle these correctly.

The `trace!` docstring also promises that the return value will always be
equal to the given input. This didn't hold before.
2025-12-04 11:22:52 +01:00
Peter Taoussanis
917b1b408e [doc] Clarify that signal content is lazy 2025-12-04 11:22:52 +01:00
Peter Taoussanis
125e006753 [nop] Housekeeping 2025-12-04 11:22:52 +01:00
Peter Taoussanis
f7006f31fe [nop] Update CHANGELOG 2025-12-04 11:22:52 +01:00
Peter Taoussanis
c6a71652d7 v1.2.0-SNAPSHOT 2025-12-04 11:22:52 +01:00
13 changed files with 216 additions and 144 deletions

View file

@ -1,6 +1,57 @@
This project uses [**Break Versioning**](https://www.taoensso.com/break-versioning). This project uses [**Break Versioning**](https://www.taoensso.com/break-versioning).
--- ---
# `v1.2.1` (2025-12-16)
## 📦 Dependencies
Available on Clojars:
1. [Telemere](https://clojars.org/com.taoensso/telemere/versions/1.2.1) - main dep
2. [SLF4J provider](https://clojars.org/com.taoensso/telemere-slf4j/versions/1.2.1) - extra dep to [send Java logging](https://github.com/taoensso/telemere/wiki/3-Config#java-logging) to Telemere
This project uses [Break Versioning](https://www.taoensso.com/break-versioning).
## Release notes
This is a **hotfix release** to fix a regression in v1.2.0 that prevented errors from correctly appearing via the Timbre->Telemere appender.
This should be a safe upgrade for users of v1.2.0, apologies for the trouble! - Peter Taoussanis
---
# `v1.2.0` (2025-12-09)
## 📦 Dependencies
Available on Clojars:
1. [Telemere](https://clojars.org/com.taoensso/telemere/versions/1.2.0) - main dep
2. [SLF4J provider](https://clojars.org/com.taoensso/telemere-slf4j/versions/1.2.0) - extra dep to [send Java logging](https://github.com/taoensso/telemere/wiki/3-Config#java-logging) to Telemere
This project uses [Break Versioning](https://www.taoensso.com/break-versioning).
## Release notes
This is a **maintenance and feature release** that should be a safe upgrade for users of v1.1.x, though there have been a few small **changes to signal content** relevant to a very small number of users (see the ➤ items below).
Please **report any unexpected problems** on [GitHub](https://github.com/taoensso/telemere/issues) or the [Slack channel](https://www.taoensso.com/telemere/slack) 🙏 - [Peter Taoussanis](https://www.taoensso.com)
## Since `v1.1.0` (2025-08-22)
- ➤ **\[mod]** SLF4J->Telemere backend: move noisy stuff out of signal data \[e6ce33d]
- ➤ **\[mod]** Timbre shim API: move noisy `:vargs` out of signal data \[cc680b0
- \[mod] [fix] Timbre->Telemere appender: de-duplicate output formatting \[47af803]
- \[mod] [fix] Timbre->Telemere appender: fix callsite coords \[b56e1c4]
- \[fix] OpenTelemetry handler: add missing line info to output \[6155713]
- \[fix] Correctly handle nil `:run` opt \[8a3ae14]
- \[new] OpenTelemetry handler: support spans created outside Telemere \[a6fc4ad]
- \[new] [#68] Add config to skip host and/or thread info \[a883df3]
- \[doc] Clarify that signal content is lazy \[917b1b4]
---
# `v1.1.0` (2025-08-22) # `v1.1.0` (2025-08-22)
## 📦 Dependencies ## 📦 Dependencies
@ -8,15 +59,17 @@ This project uses [**Break Versioning**](https://www.taoensso.com/break-versioni
Available on Clojars: Available on Clojars:
1. [Telemere](https://clojars.org/com.taoensso/telemere/versions/1.1.0) - main dep 1. [Telemere](https://clojars.org/com.taoensso/telemere/versions/1.1.0) - main dep
2. [SLF4J provider](https://clojars.org/com.taoensso/telemere-slf4j/versions/1.0.1) - extra dep to [send Java logging](https://github.com/taoensso/telemere/wiki/3-Config#java-logging) to Telemere 2. [SLF4J provider](https://clojars.org/com.taoensso/telemere-slf4j/versions/1.1.0) - extra dep to [send Java logging](https://github.com/taoensso/telemere/wiki/3-Config#java-logging) to Telemere
This project uses [Break Versioning](https://www.taoensso.com/break-versioning). This project uses [Break Versioning](https://www.taoensso.com/break-versioning).
## Release notes
This is a **maintenance release** that fixes a few minor issues, improves docs, and adds some extra API flexibility. It should be a safe upgrade for all users of v1.x. This is a **maintenance release** that fixes a few minor issues, improves docs, and adds some extra API flexibility. It should be a safe upgrade for all users of v1.x.
Please **report any unexpected problems** on [GitHub](https://github.com/taoensso/telemere/issues) or the [Slack channel](https://www.taoensso.com/telemere/slack) 🙏 - [Peter Taoussanis](https://www.taoensso.com) Please **report any unexpected problems** on [GitHub](https://github.com/taoensso/telemere/issues) or the [Slack channel](https://www.taoensso.com/telemere/slack) 🙏 - [Peter Taoussanis](https://www.taoensso.com)
## Since v1.0.01 (2025-05-27) ## Since v1.0.1 (2025-05-27)
- \[fix] `:trace` level JS console logging \[b2a8b66] - \[fix] `:trace` level JS console logging \[b2a8b66]
- \[fix] Clj-kondo warnings for `with-signal/s` \[269c58d] - \[fix] Clj-kondo warnings for `with-signal/s` \[269c58d]

View file

@ -1,5 +1,5 @@
<a href="https://www.taoensso.com/clojure" title="More stuff by @ptaoussanis at www.taoensso.com"><img src="https://www.taoensso.com/open-source.png" alt="Taoensso open source" width="340"/></a> <a href="https://www.taoensso.com/clojure" title="More stuff by @ptaoussanis at www.taoensso.com"><img src="https://www.taoensso.com/open-source.png" alt="Taoensso open source" width="340"/></a>
[**API**][cljdoc] | [**Wiki**][GitHub wiki] | [Slack channel][] | Latest release: [v1.1.0](../../releases/tag/v1.1.0) (2025-08-22) [**API**][cljdoc] | [**Wiki**][GitHub wiki] | [Slack][] | Latest release: [v1.2.1](../../releases/tag/v1.2.1) (2025-12-16)
[![Clj tests][Clj tests SVG]][Clj tests URL] [![Clj tests][Clj tests SVG]][Clj tests URL]
[![Cljs tests][Cljs tests SVG]][Cljs tests URL] [![Cljs tests][Cljs tests SVG]][Cljs tests URL]
@ -200,7 +200,7 @@ See [examples.cljc](https://github.com/taoensso/telemere/blob/master/examples.cl
## Comparisons ## Comparisons
- Telemere [compared](../../wiki/5-Migrating#from-timbre) to [Timbre](https://www.taoensso.com/timbre) (Telemere's predecessor) - Telemere [compared](../../wiki/5-Migrating#from-timbre) to [Timbre](https://www.taoensso.com/timbre) (Telemere's predecessor)
- Telemere [compared](../../wiki/6-FAQ#how-does-telemere-compare-to-mulog) to [μ/log](https://github.com/BrunoBonacci/mulog) (structured micro-logging library) - Telemere [compared](../../wiki/6-FAQ#how-does-telemere-compare-to-%CE%BClog) to [μ/log](https://github.com/BrunoBonacci/mulog) (structured micro-logging library)
## Videos ## Videos
@ -314,7 +314,7 @@ See [here](../../wiki/8-Community) for community resources.
- [Wiki][GitHub wiki] (getting started, usage, etc.) - [Wiki][GitHub wiki] (getting started, usage, etc.)
- API reference via [cljdoc][cljdoc] - API reference via [cljdoc][cljdoc]
- Extensive [internal help](#internal-help) (no need to leave your IDE) - Extensive [internal help](#internal-help) (no need to leave your IDE)
- Support via [Slack channel][] or [GitHub issues][] - Support via [Slack][] or [GitHub issues][]
- [General observability tips](../../wiki/7-Tips) (advice on building and maintaining observable Clojure/Script systems, and getting the most out of Telemere) - [General observability tips](../../wiki/7-Tips) (advice on building and maintaining observable Clojure/Script systems, and getting the most out of Telemere)
## Funding ## Funding
@ -331,7 +331,7 @@ Licensed under [EPL 1.0](LICENSE.txt) (same as Clojure).
[GitHub releases]: ../../releases [GitHub releases]: ../../releases
[GitHub issues]: ../../issues [GitHub issues]: ../../issues
[GitHub wiki]: ../../wiki [GitHub wiki]: ../../wiki
[Slack channel]: https://www.taoensso.com/telemere/slack [Slack]: https://www.taoensso.com/telemere/slack
[Peter Taoussanis]: https://www.taoensso.com [Peter Taoussanis]: https://www.taoensso.com
[sponsor]: https://www.taoensso.com/sponsor [sponsor]: https://www.taoensso.com/sponsor

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 384 KiB

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

View file

@ -1,4 +1,4 @@
(defproject com.taoensso/telemere "1.1.0" (defproject com.taoensso/telemere "1.2.1"
:author "Peter Taoussanis <https://www.taoensso.com>" :author "Peter Taoussanis <https://www.taoensso.com>"
:description "Structured logs and telemetry for Clojure/Script" :description "Structured logs and telemetry for Clojure/Script"
:url "https://www.taoensso.com/telemere" :url "https://www.taoensso.com/telemere"
@ -10,15 +10,15 @@
:scm {:name "git" :url "https://github.com/taoensso/telemere"} :scm {:name "git" :url "https://github.com/taoensso/telemere"}
:dependencies :dependencies
[[com.taoensso/encore "3.153.1"]] [[com.taoensso/encore "3.159.0"]]
:test-paths ["test" #_"src"] :test-paths ["test" #_"src"]
:profiles :profiles
{;; :default [:base :system :user :provided :dev] {;; :default [:base :system :user :provided :dev]
:provided {:dependencies [[org.clojure/clojurescript "1.12.42"] :provided {:dependencies [[org.clojure/clojurescript "1.12.134"]
[org.clojure/clojure "1.11.4"]]} [org.clojure/clojure "1.11.4"]]}
:c1.12 {:dependencies [[org.clojure/clojure "1.12.1"]]} :c1.12 {:dependencies [[org.clojure/clojure "1.12.3"]]}
:c1.11 {:dependencies [[org.clojure/clojure "1.11.4"]]} :c1.11 {:dependencies [[org.clojure/clojure "1.11.4"]]}
:c1.10 {:dependencies [[org.clojure/clojure "1.10.3"]]} :c1.10 {:dependencies [[org.clojure/clojure "1.10.3"]]}
@ -47,18 +47,18 @@
:dependencies :dependencies
[[org.clojure/core.async "1.8.741"] [[org.clojure/core.async "1.8.741"]
[org.clojure/test.check "1.1.1"] [org.clojure/test.check "1.1.2"]
[org.clojure/tools.logging "1.3.0"] [org.clojure/tools.logging "1.3.0"]
[org.slf4j/slf4j-api "2.0.17"] [org.slf4j/slf4j-api "2.0.17"]
[com.taoensso/telemere-slf4j "1.1.0"] [com.taoensso/telemere-slf4j "1.2.1"]
#_[org.slf4j/slf4j-simple "2.0.16"] #_[org.slf4j/slf4j-simple "2.0.16"]
#_[org.slf4j/slf4j-nop "2.0.16"] #_[org.slf4j/slf4j-nop "2.0.16"]
#_[io.github.paintparty/bling "0.4.2"] #_[io.github.paintparty/bling "0.4.2"]
;;; For optional handlers ;;; For optional handlers
[io.opentelemetry/opentelemetry-api "1.53.0"] [io.opentelemetry/opentelemetry-api "1.57.0"]
[io.opentelemetry/opentelemetry-sdk-extension-autoconfigure "1.53.0"] [io.opentelemetry/opentelemetry-sdk-extension-autoconfigure "1.57.0"]
[io.opentelemetry/opentelemetry-exporter-otlp "1.53.0"] [io.opentelemetry/opentelemetry-exporter-otlp "1.57.0"]
#_[io.opentelemetry/opentelemetry-exporters-jaeger "0.9.1"] #_[io.opentelemetry/opentelemetry-exporters-jaeger "0.9.1"]
[metosin/jsonista "0.3.13"] [metosin/jsonista "0.3.13"]
[com.draines/postal "2.0.5"] [com.draines/postal "2.0.5"]

View file

@ -9,12 +9,12 @@ All options are available for all signal creator calls:
Defaults to `:auto` for tracing signals, and nil otherwise Defaults to `:auto` for tracing signals, and nil otherwise
`:msg` --------- Arb app-level ?message to incl. in signal: str or vec of strs to join (with `\space`), may be a delay `:msg` --------- Arb app-level ?message to incl. in signal: str or vec of strs to join (with `\space`), may be a delay
`:data` -------- Arb app-level ?data to incl. in signal: usu. a map `:data` -------- Arb app-level ?data to incl. in signal: usu. a map, LAZY! [3]
`:error` ------- Arb app-level ?error to incl. in signal: platform error [2] `:error` ------- Arb app-level ?error to incl. in signal: platform error [2]
`:run` --------- ?form to execute UNCONDITIONALLY; will incl. `:run-val` in signal `:run` --------- ?form to execute UNCONDITIONALLY; will incl. `:run-val` in signal
`:do` ---------- ?form to execute conditionally (iff signal allowed), before establishing `:let` ?binding `:do` ---------- ?form to execute conditionally (iff signal allowed) and LAZILY [3], before establishing `:let` ?binding
`:let` --------- ?bindings to establish conditionally (iff signal allowed), BEFORE evaluating `:data` and `:msg` (useful!) `:let` --------- ?bindings to establish conditionally (iff signal allowed) and LAZILY [3], BEFORE evaluating `:data` and `:msg` (useful!)
`:parent` ------ Custom ?{:keys [id uid]} to override auto (dynamic) parent signal tracing info `:parent` ------ Custom ?{:keys [id uid]} to override auto (dynamic) parent signal tracing info
`:root` -------- Custom ?{:keys [id uid]} to override auto (dynamic) root signal tracing info `:root` -------- Custom ?{:keys [id uid]} to override auto (dynamic) root signal tracing info
@ -37,9 +37,13 @@ All options are available for all signal creator calls:
<kvs> ---------- Other arb app-level ?kvs to incl. in signal. Typically NOT included in <kvs> ---------- Other arb app-level ?kvs to incl. in signal. Typically NOT included in
handler output, so a great way to provide custom data/opts for use handler output, so a great way to provide custom data/opts for use
(only) by custom transforms/handlers. (only) by custom transforms/handlers. LAZY! [3]
If anything is unclear, please ping me (@ptaoussanis) so that I can improve these docs! If anything is unclear, please ping me (@ptaoussanis) so that I can improve these docs!
[1] `java.time.Instant` or `js/Date` [1] `java.time.Instant` or `js/Date`
[2] `java.lang.Throwable` or `js/Error` [2] `java.lang.Throwable` or `js/Error`
[3] Most Telemere signal content is evaluated CONDITIONALLY (iff signal allowed),
LAZILY (when signal is created), and on the HANDLING THREAD (not logging thread).
This allows efficient filtering, better control+monitoring of back pressure,
conditional effects, etc. Ref. <https://www.taoensso.com/telemere/flow> for visual!

View file

@ -31,7 +31,7 @@
(remove-ns (symbol (str *ns*))) (remove-ns (symbol (str *ns*)))
(:api (enc/interns-overview))) (:api (enc/interns-overview)))
(enc/assert-min-encore-version [3 153 1]) (enc/assert-min-encore-version [3 159 0])
;;;; Shared signal API ;;;; Shared signal API

View file

@ -38,7 +38,10 @@
(def enabled:otel-tracing? (def enabled:otel-tracing?
"Documented at `taoensso.telemere/otel-tracing?`." "Documented at `taoensso.telemere/otel-tracing?`."
(enc/get-env {:as :bool, :default present:otel?} (enc/get-env {:as :bool, :default present:otel?}
:taoensso.telemere/otel-tracing<.platform>)))) :taoensso.telemere/otel-tracing<.platform>))
(def enabled:incl-host-info? "Include `:host` info in signals by default?" (enc/get-env {:as :bool, :default true} :taoensso.telemere/incl-host-info))
(def enabled:incl-thread-info? "Include `:thread` info in signals by default?" (enc/get-env {:as :bool, :default true} :taoensso.telemere/incl-thread-info))))
(def uid-kind (def uid-kind
"Documented at `taoensso.telemere/*uid-fn*`." "Documented at `taoensso.telemere/*uid-fn*`."
@ -170,8 +173,8 @@
(defn default-trace-msg (defn default-trace-msg
[form value error nsecs] [form value error nsecs]
(if error (if error
(str form " !> " (truss/ex-type error)) (str (if (nil? form) "nil" form) " !> " (truss/ex-type error))
(str form " => " value))) (str (if (nil? form) "nil" form) " => " (if (nil? value) "nil" value))))
(comment (comment
(default-trace-msg "(+ 1 2)" 3 nil 12345) (default-trace-msg "(+ 1 2)" 3 nil 12345)
@ -524,14 +527,16 @@
clj? (not cljs?) clj? (not cljs?)
opts (merge {:kind :generic, :level :info} base-opts opts) opts (merge {:kind :generic, :level :info} base-opts opts)
{run-form :run} opts
run-form? (contains? opts :run)
run-form (get opts :run)
ns-form* (get opts :ns :auto) ns-form* (get opts :ns :auto)
ns-form (auto-> ns-form* (str *ns*)) ns-form (auto-> ns-form* (str *ns*))
show-run-val (get opts :run-val '_run-val) show-run-val (get opts :run-val '_run-val)
show-run-form show-run-form
(when run-form (when run-form?
(get opts :run-form (get opts :run-form
(if (and (if (and
(enc/list-form? run-form) (enc/list-form? run-form)
@ -564,15 +569,15 @@
id-form :id id-form :id
level-form :level} opts level-form :level} opts
trace? (get opts :trace? (boolean run-form)) trace? (get opts :trace? run-form?)
_ _
(when-not (contains? #{true false nil} trace?) (when-not (contains? #{true false nil} trace?)
(truss/ex-info! (truss/ex-info!
(str "Signal needs compile-time `:trace?` value at " (str "Signal needs compile-time `:trace?` value at "
(sigs/format-callsite ns-form coords)))) (sigs/format-callsite ns-form coords))))
host-form (auto-> (get opts :host :auto) (when clj? `(enc/host-info))) host-form (auto-> (get opts :host :auto) (when (and clj? enabled:incl-host-info?) `(enc/host-info)))
thread-form (auto-> (get opts :thread :auto) (when clj? `(enc/thread-info))) thread-form (auto-> (get opts :thread :auto) (when (and clj? enabled:incl-thread-info?) `(enc/thread-info)))
inst-form (auto-> (get opts :inst :auto) `(enc/now-inst*)) inst-form (auto-> (get opts :inst :auto) `(enc/now-inst*))
parent-form (get opts :parent `*trace-parent*) parent-form (get opts :parent `*trace-parent*)
@ -607,7 +612,7 @@
(dissoc opts (dissoc opts
:elidable? :coords :inst :uid :xfn :xfn+ :kvs+, :elidable? :coords :inst :uid :xfn :xfn+ :kvs+,
:sample :ns :kind :id :level :filter :when #_:limit #_:limit-by, :sample :ns :kind :id :level :filter :when #_:limit #_:limit-by,
:ctx :ctx+ :parent #_:trace?, :do :let :data :msg :error, :ctx :ctx+ :parent :trace?, :do :let :data :msg :error,
:run :run-form :run-val, :elide? :allow? #_:callsite-id, :run :run-form :run-val, :elide? :allow? #_:callsite-id,
:host :thread :otel/context))] :host :thread :otel/context))]
@ -619,7 +624,7 @@
_ ; Compile-time validation _ ; Compile-time validation
(do (do
(when (and run-form error-form) ; Ambiguous source of error (when (and run-form? error-form) ; Ambiguous source of error
(truss/ex-info! (truss/ex-info!
(str "Signal cannot have both `:run` and `:error` opts at " (str "Signal cannot have both `:run` and `:error` opts at "
(sigs/format-callsite ns-form coords)))) (sigs/format-callsite ns-form coords))))
@ -631,18 +636,18 @@
signal-form signal-form
(let [record-form (let [record-form
(let [clause [(if run-form :run :no-run) (if clj? :clj :cljs)]] (let [clause [(if run-form? :run :no-run) (if clj? :clj :cljs)]]
(case clause (case clause
[:run :clj ] `(Signal. 1 ~'__inst ~'__uid, ~'__ns ~coords ~host-form ~'__thread ~'__otel-context1, ~sample-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~'_msg_, ~'_run-err '~show-run-form ~show-run-val ~'_end-inst ~'_run-nsecs) [:run :clj ] `(Signal. 1 ~'__inst ~'__uid, ~'__ns ~coords ~host-form ~'__thread ~'__otel-context, ~sample-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~'_msg_, ~'_run-err '~show-run-form ~show-run-val ~'_end-inst ~'_run-nsecs)
[:run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~'__ns ~coords ~sample-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~'_msg_, ~'_run-err '~show-run-form ~show-run-val ~'_end-inst ~'_run-nsecs) [:run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~'__ns ~coords ~sample-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~'_msg_, ~'_run-err '~show-run-form ~show-run-val ~'_end-inst ~'_run-nsecs)
[:no-run :clj ] `(Signal. 1 ~'__inst ~'__uid, ~'__ns ~coords ~host-form ~'__thread ~'__otel-context1, ~sample-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil) [:no-run :clj ] `(Signal. 1 ~'__inst ~'__uid, ~'__ns ~coords ~host-form ~'__thread ~'__otel-context, ~sample-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil)
[:no-run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~'__ns ~coords ~sample-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil) [:no-run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~'__ns ~coords ~sample-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil)
(truss/ex-info! (truss/ex-info!
(str "Unexpected signal constructor args at " (str "Unexpected signal constructor args at "
(sigs/format-callsite ns-form coords))))) (sigs/format-callsite ns-form coords)))))
record-form record-form
(if-not run-form (if-not run-form?
record-form record-form
`(let [~(with-meta '_run-result {:tag `RunResult}) ~'__run-result `(let [~(with-meta '_run-result {:tag `RunResult}) ~'__run-result
~'_run-nsecs (.-run-nsecs ~'_run-result) ~'_run-nsecs (.-run-nsecs ~'_run-result)
@ -674,17 +679,31 @@
(do signal#))))) (do signal#)))))
;; Trade-off: avoid double `run-form` expansion ;; Trade-off: avoid double `run-form` expansion
run-fn-form (when run-form `(fn [] ~run-form)) run-fn-form (when run-form? `(fn [] ~run-form))
run-form* (when run-form `(~'__run-fn-form)) run-form* (when run-form? `(~'__run-fn-form))
into-let-form binds-form-base
`[~'__inst ~inst-form
~'__thread ~thread-form
~'__root0 ~root-form0 ; ?{:keys [id uid]}
~'__otel-context
~(when (and clj? enabled:otel-tracing?)
(if run-form?
`(otel-context+span ~'__id ~'__inst ~(get opts :otel/context `(otel-context)) ~(get opts :otel/span-kind))
(do (get opts :otel/context `(otel-context)))))
~'__uid
~(if (and clj? enabled:otel-tracing? trace?)
(auto-> uid-form `(or (otel-span-id ~'__otel-context) (com.taoensso.encore.Ids/genHexId16)))
(auto-> uid-form `(taoensso.telemere/*uid-fn* (if ~'__root0 false true))))]
binds-form-more
(enc/cond! (enc/cond!
(not trace?) ; Don't trace (not trace?) ; Non-tracing signal
`[~'__otel-context1 nil `[~'__root1 ~'__root0 ; Retain, but don't establish
~'__uid ~(auto-> uid-form `(taoensso.telemere/*uid-fn* (if ~'__root0 false true)))
~'__root1 ~'__root0 ; Retain, but don't establish
~'__run-result ~'__run-result
~(when run-form ~(when run-form?
`(let [t0# (enc/now-nano*)] `(let [t0# (enc/now-nano*)]
(truss/try* (truss/try*
(do (RunResult. ~run-form* nil (- (enc/now-nano*) t0#))) (do (RunResult. ~run-form* nil (- (enc/now-nano*) t0#)))
@ -692,11 +711,9 @@
;; Trace without OpenTelemetry ;; Trace without OpenTelemetry
(or cljs? (not enabled:otel-tracing?)) (or cljs? (not enabled:otel-tracing?))
`[~'__otel-context1 nil `[~'__root1 (or ~'__root0 ~(when trace? `{:id ~'__id, :uid ~'__uid}))
~'__uid ~(auto-> uid-form `(taoensso.telemere/*uid-fn* (if ~'__root0 false true)))
~'__root1 (or ~'__root0 ~(when trace? `{:id ~'__id, :uid ~'__uid}))
~'__run-result ~'__run-result
~(when run-form ~(when run-form?
`(binding [*trace-root* ~'__root1 `(binding [*trace-root* ~'__root1
*trace-parent* {:id ~'__id, :uid ~'__uid}] *trace-parent* {:id ~'__id, :uid ~'__uid}]
(let [t0# (enc/now-nano*)] (let [t0# (enc/now-nano*)]
@ -706,20 +723,17 @@
;; Trace with OpenTelemetry ;; Trace with OpenTelemetry
(and clj? enabled:otel-tracing?) (and clj? enabled:otel-tracing?)
`[~'__otel-context0 ~(get opts :otel/context `(otel-context)) ; Context `[~'__root1
~'__otel-context1 ~(if run-form `(otel-context+span ~'__id ~'__inst ~'__otel-context0 ~(get opts :otel/span-kind)) ~'__otel-context0)
~'__uid ~(auto-> uid-form `(or (otel-span-id ~'__otel-context1) (com.taoensso.encore.Ids/genHexId16)))
~'__root1
(or ~'__root0 (or ~'__root0
~(when trace? ~(when trace?
`{:id ~'__id, :uid (or (otel-trace-id ~'__otel-context1) (com.taoensso.encore.Ids/genHexId32))})) `{:id ~'__id, :uid (or (otel-trace-id ~'__otel-context) (com.taoensso.encore.Ids/genHexId32))}))
~'__run-result ~'__run-result
~(when run-form ~(when run-form?
`(binding [*otel-context* ~'__otel-context1 `(binding [*otel-context* ~'__otel-context
*trace-root* ~'__root1 *trace-root* ~'__root1
*trace-parent* {:id ~'__id, :uid ~'__uid}] *trace-parent* {:id ~'__id, :uid ~'__uid}]
(let [otel-scope# (.makeCurrent ~'__otel-context1) (let [otel-scope# (.makeCurrent ~'__otel-context)
t0# (enc/now-nano*)] t0# (enc/now-nano*)]
(truss/try* (truss/try*
(do (RunResult. ~run-form* nil (- (enc/now-nano*) t0#))) (do (RunResult. ~run-form* nil (- (enc/now-nano*) t0#)))
@ -736,11 +750,8 @@
(enc/if-not ~allow? (enc/if-not ~allow?
~run-form* ~run-form*
(let [~'__inst ~inst-form (let [~@binds-form-base
~'__thread ~thread-form ~@binds-form-more
~'__root0 ~root-form0 ; ?{:keys [id uid]}
~@into-let-form ; Inject conditional bindings
signal# ~signal-delay-form] signal# ~signal-delay-form]
(dispatch-signal! (dispatch-signal!

View file

@ -220,14 +220,14 @@
(if (or common-attrs trace-attrs) (if (or common-attrs trace-attrs)
(let [ab (Attributes/builder)] (let [ab (Attributes/builder)]
(when-let [ns (get signal :ns)] (.put ab "ns" (str ns))) (when-let [ns (get signal :ns)] (.put ab "ns" (str ns)))
(when-let [line (get signal :line)] (.put ab "line" (long line))) (when-let [line (enc/get-in* signal [:coords 0])] (.put ab "line" (long line)))
(when-let [attrs common-attrs] (put-attrs! ab attrs)) (when-let [attrs common-attrs] (put-attrs! ab attrs))
(when-let [attrs trace-attrs] (put-attrs! ab attrs)) (when-let [attrs trace-attrs] (put-attrs! ab attrs))
(.build ab)) (.build ab))
;; Common case ;; Common case
(when-let [ns (get signal :ns)] (when-let [ns (get signal :ns)]
(if-let [line (get signal :line)] (if-let [line (enc/get-in* signal [:coords 0])]
(Attributes/of ak-ns ns, ak-line (long line)) (Attributes/of ak-ns ns, ak-line (long line))
(Attributes/of ak-ns ns))))))) (Attributes/of ak-ns ns)))))))

View file

@ -35,7 +35,7 @@
(enc/format* pattern vargs) (enc/format* pattern vargs)
(enc/str-join " " (map arg-str) vargs)))] (enc/str-join " " (map arg-str) vargs)))]
[error msg {:vargs vargs}]) [error msg vargs])
(let [md (if (and (map? v0) (get (meta v0) :meta)) v0 nil) (let [md (if (and (map? v0) (get (meta v0) :meta)) v0 nil)
error (get md :err) error (get md :err)
@ -49,7 +49,7 @@
(enc/format* pattern vargs) (enc/format* pattern vargs)
(enc/str-join " " (map arg-str) vargs)))] (enc/str-join " " (map arg-str) vargs)))]
[error msg (when-not (empty? vargs) {:vargs vargs})]))))) [error msg (when-not (empty? vargs) vargs)])))))
(comment (comment
(parse-vargs true [ "hello %s" "stu"]) (parse-vargs true [ "hello %s" "stu"])
@ -63,13 +63,13 @@
[level format-msg? vargs] [level format-msg? vargs]
(truss/keep-callsite (truss/keep-callsite
`(when (impl/signal-allowed? {:kind :log, :level ~level, :id shim-id}) `(when (impl/signal-allowed? {:kind :log, :level ~level, :id shim-id})
(let [[error# msg# data#] (parse-vargs ~format-msg? ~vargs)] (let [[error# msg# vargs#] (parse-vargs ~format-msg? ~vargs)]
(tel/log! (tel/log!
{:allow? true {:allow? true
:level ~level :level ~level
:id shim-id :id shim-id
:error error# :error error#
:data data#} :timbre/vargs vargs#}
msg#) msg#)
nil))))) nil)))))
@ -190,8 +190,11 @@
:min-level nil :min-level nil
:fn :fn
(fn [data] (fn [data]
(let [{:keys [instant level context ?err output_ (let [{:keys [instant level context ?err msg-type vargs
?ns-str ?file ?line ?column]} data] ?ns-str ?file ?line ?column]} data
format-msg? (enc/identical-kw? msg-type :f)
[_error msg vargs] (parse-vargs format-msg? vargs)]
(taoensso.telemere/signal! (taoensso.telemere/signal!
{:kind :timbre {:kind :timbre
@ -200,9 +203,10 @@
:ctx+ context :ctx+ context
:ns ?ns-str :ns ?ns-str
:file ?file :coords (when ?line [?line ?column])
:line ?line :file ?file ; Non-standard, goes to kvs
:column ?column
:error ?err :error ?err
:msg (force output_)})))}) :msg (when msg-type msg)
:timbre/vargs vargs})))})

View file

@ -594,7 +594,8 @@
(let [{rv :value, [sv] :signals} (with-sigs (tel/log!? {:allow? false} "msg")) ] [(is (= rv nil)) (is (nil? sv))])]) (let [{rv :value, [sv] :signals} (with-sigs (tel/log!? {:allow? false} "msg")) ] [(is (= rv nil)) (is (nil? sv))])])
(testing "trace!" ; ?id + run => unconditional run result (value or throw) (testing "trace!" ; ?id + run => unconditional run result (value or throw)
[(let [{rv :value, [sv] :signals} (with-sigs (tel/trace! (+ 1 2))) ] [(is (= rv 3)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id nil, :msg_ "(+ 1 2) => 3"}))]) [(let [{rv :value, [sv] :signals} (with-sigs (tel/trace! nil)) ] [(is (= rv nil)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id nil, :msg_ "nil => nil"}))])
(let [{rv :value, [sv] :signals} (with-sigs (tel/trace! (+ 1 2))) ] [(is (= rv 3)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id nil, :msg_ "(+ 1 2) => 3"}))])
(let [{rv :value, [sv] :signals} (with-sigs (tel/trace! {:msg nil} (+ 1 2))) ] [(is (= rv 3)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id nil, :msg_ nil}))]) (let [{rv :value, [sv] :signals} (with-sigs (tel/trace! {:msg nil} (+ 1 2))) ] [(is (= rv 3)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id nil, :msg_ nil}))])
(let [{rv :value, [sv] :signals} (with-sigs (tel/trace! :id1 (+ 1 2))) ] [(is (= rv 3)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id :id1}))]) (let [{rv :value, [sv] :signals} (with-sigs (tel/trace! :id1 (+ 1 2))) ] [(is (= rv 3)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id :id1}))])
(let [{rv :value, [sv] :signals} (with-sigs (tel/trace! {:id :id1} (+ 1 2))) ] [(is (= rv 3)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id :id1}))]) (let [{rv :value, [sv] :signals} (with-sigs (tel/trace! {:id :id1} (+ 1 2))) ] [(is (= rv 3)) (is (sm? sv {:kind :trace, :coords coords?, :level :info, :id :id1}))])
@ -726,7 +727,7 @@
(is (sm? (with-sig (-> (.atWarn sl) (.log "Hello"))) {:level :warn, :ns "my.class", :kind :slf4j, :msg_ "Hello", :inst enc/inst?}) "Fluent API: warn basics")]) (is (sm? (with-sig (-> (.atWarn sl) (.log "Hello"))) {:level :warn, :ns "my.class", :kind :slf4j, :msg_ "Hello", :inst enc/inst?}) "Fluent API: warn basics")])
(testing "Message formatting" (testing "Message formatting"
(let [msgp "x={},y={}", expected {:msg_ "x=1,y=2", :data {:slf4j/args ["1" "2"]}}] (let [msgp "x={},y={}", expected {:msg_ "x=1,y=2", :slf4j/args (fn [objs] (= (vec objs) ["1" "2"]))}]
[(is (sm? (with-sig (.info sl msgp "1" "2")) expected) "Legacy API: formatted message, raw args") [(is (sm? (with-sig (.info sl msgp "1" "2")) expected) "Legacy API: formatted message, raw args")
(is (sm? (with-sig (-> (.atInfo sl) (.setMessage msgp) (.addArgument "1") (.addArgument "2") (.log))) expected) "Fluent API: formatted message, raw args")])) (is (sm? (with-sig (-> (.atInfo sl) (.setMessage msgp) (.addArgument "1") (.addArgument "2") (.log))) expected) "Fluent API: formatted message, raw args")]))
@ -737,8 +738,8 @@
m2 (#'slf4j/est-marker! "M2") m2 (#'slf4j/est-marker! "M2")
cm (#'slf4j/est-marker! "Compound" "M1" "M2")] cm (#'slf4j/est-marker! "Compound" "M1" "M2")]
[(is (sm? (with-sig (.info sl cm "Hello")) {:data {:slf4j/marker-names #{"Compound" "M1" "M2"}}}) "Legacy API: markers") [(is (sm? (with-sig (.info sl cm "Hello")) {:slf4j/markers #{"Compound" "M1" "M2"}}) "Legacy API: markers")
(is (sm? (with-sig (-> (.atInfo sl) (.addMarker m1) (.addMarker cm) (.log))) {:data {:slf4j/marker-names #{"Compound" "M1" "M2"}}}) "Fluent API: markers")])) (is (sm? (with-sig (-> (.atInfo sl) (.addMarker m1) (.addMarker cm) (.log))) {:slf4j/markers #{"Compound" "M1" "M2"}}) "Fluent API: markers")]))
(testing "Errors" (testing "Errors"
[(is (sm? (with-sig (.warn sl "An error" ^Throwable ex1)) {:level :warn, :error ex1}) "Legacy API: errors") [(is (sm? (with-sig (.warn sl "An error" ^Throwable ex1)) {:level :warn, :error ex1}) "Legacy API: errors")
@ -753,15 +754,15 @@
;;;; Timbre shim ;;;; Timbre shim
(deftest _timbre-shim (deftest _timbre-shim
[(is (sm? (with-sig (timbre/log :warn "x1" nil "x2")) {:kind :log, :level :warn, :id timbre/shim-id, :msg_ "x1 nil x2", :data {:vargs ["x1" nil "x2"]}, :ns string?})) [(is (sm? (with-sig (timbre/log :warn "x1" nil "x2")) {:kind :log, :level :warn, :id timbre/shim-id, :msg_ "x1 nil x2", :timbre/vargs ["x1" nil "x2"], :ns string?}))
(is (sm? (with-sig (timbre/info "x1" nil "x2")) {:kind :log, :level :info, :id timbre/shim-id, :msg_ "x1 nil x2", :data {:vargs ["x1" nil "x2"]}, :ns string?})) (is (sm? (with-sig (timbre/info "x1" nil "x2")) {:kind :log, :level :info, :id timbre/shim-id, :msg_ "x1 nil x2", :timbre/vargs ["x1" nil "x2"], :ns string?}))
(is (sm? (with-sig (timbre/error "x1" nil "x2")) {:kind :log, :level :error, :id timbre/shim-id, :msg_ "x1 nil x2", :data {:vargs ["x1" nil "x2"]}, :ns string?})) (is (sm? (with-sig (timbre/error "x1" nil "x2")) {:kind :log, :level :error, :id timbre/shim-id, :msg_ "x1 nil x2", :timbre/vargs ["x1" nil "x2"], :ns string?}))
(is (sm? (with-sig (timbre/logf :warn "%s %s %s" "x1" nil "x2")) {:kind :log, :level :warn, :id timbre/shim-id, :msg_ "x1 nil x2", :data {:vargs ["x1" nil "x2"]}, :ns string?})) (is (sm? (with-sig (timbre/logf :warn "%s %s %s" "x1" nil "x2")) {:kind :log, :level :warn, :id timbre/shim-id, :msg_ "x1 nil x2", :timbre/vargs ["x1" nil "x2"], :ns string?}))
(is (sm? (with-sig (timbre/infof "%s %s %s" "x1" nil "x2")) {:kind :log, :level :info, :id timbre/shim-id, :msg_ "x1 nil x2", :data {:vargs ["x1" nil "x2"]}, :ns string?})) (is (sm? (with-sig (timbre/infof "%s %s %s" "x1" nil "x2")) {:kind :log, :level :info, :id timbre/shim-id, :msg_ "x1 nil x2", :timbre/vargs ["x1" nil "x2"], :ns string?}))
(is (sm? (with-sig (timbre/errorf "%s %s %s" "x1" nil "x2")) {:kind :log, :level :error, :id timbre/shim-id, :msg_ "x1 nil x2", :data {:vargs ["x1" nil "x2"]}, :ns string?})) (is (sm? (with-sig (timbre/errorf "%s %s %s" "x1" nil "x2")) {:kind :log, :level :error, :id timbre/shim-id, :msg_ "x1 nil x2", :timbre/vargs ["x1" nil "x2"], :ns string?}))
(is (sm? (with-sig (timbre/info ex1 "x1" "x2")) {:kind :log, :level :info, :error ex1, :msg_ "x1 x2", :data {:vargs ["x1" "x2"]}}) "First-arg error") (is (sm? (with-sig (timbre/info ex1 "x1" "x2")) {:kind :log, :level :info, :error ex1, :msg_ "x1 x2", :timbre/vargs ["x1" "x2"]}) "First-arg error")
(is (sm? (with-sig (timbre/spy :info "my-name" (+ 1 2))) {:kind :spy, :level :info, :id timbre/shim-id, :msg_ "my-name => 3", :ns string?})) (is (sm? (with-sig (timbre/spy :info "my-name" (+ 1 2))) {:kind :spy, :level :info, :id timbre/shim-id, :msg_ "my-name => 3", :ns string?}))
(is (sm? (tel/with-min-level :debug (with-sig (timbre/spy (+ 1 2)))) {:kind :spy, :level :debug, :id timbre/shim-id, :msg_ "(+ 1 2) => 3", :ns string?})) (is (sm? (tel/with-min-level :debug (with-sig (timbre/spy (+ 1 2)))) {:kind :spy, :level :debug, :id timbre/shim-id, :msg_ "(+ 1 2) => 3", :ns string?}))

View file

@ -1,4 +1,4 @@
(defproject com.taoensso/telemere-slf4j "1.1.0" (defproject com.taoensso/telemere-slf4j "1.2.1"
:author "Peter Taoussanis <https://www.taoensso.com>" :author "Peter Taoussanis <https://www.taoensso.com>"
:description "Telemere backend/provider for SLF4J API v2" :description "Telemere backend/provider for SLF4J API v2"
:url "https://www.taoensso.com/telemere" :url "https://www.taoensso.com/telemere"
@ -16,9 +16,9 @@
:profiles :profiles
{:provided {:provided
{:dependencies {:dependencies
[[org.clojure/clojure "1.12.1"] [[org.clojure/clojure "1.12.3"]
[org.slf4j/slf4j-api "2.0.17"] [org.slf4j/slf4j-api "2.0.17"]
[com.taoensso/telemere "1.1.0"]]} [com.taoensso/telemere "1.2.1"]]}
:dev :dev
{:plugins {:plugins

View file

@ -63,13 +63,13 @@
(comment [(est-marker! "a1" "a2") (get-marker "a1") (= (get-marker "a1") (get-marker "a1"))]) (comment [(est-marker! "a1" "a2") (get-marker "a1") (= (get-marker "a1") (get-marker "a1"))])
(def ^:private marker-names (def ^:private get-marker-names
"Returns #{<MarkerName>}. Cached => assumes markers NOT modified after creation." "Returns #{<MarkerName>}. Cached => assumes markers NOT modified after creation."
;; We use `BasicMarkerFactory` so: ;; We use `BasicMarkerFactory` so:
;; 1. Our markers are just labels (no other content besides their name). ;; 1. Our markers are just labels (no other content besides their name).
;; 2. Markers with the same name are identical (enabling caching). ;; 2. Markers with the same name are identical (enabling caching).
(enc/fmemoize (enc/fmemoize
(fn marker-names [marker-or-markers] (fn get-marker-names [marker-or-markers]
(if (instance? org.slf4j.Marker marker-or-markers) (if (instance? org.slf4j.Marker marker-or-markers)
;; Single marker ;; Single marker
@ -82,12 +82,12 @@
(fn [acc ^org.slf4j.Marker in] (fn [acc ^org.slf4j.Marker in]
(if-not (.hasReferences in) (if-not (.hasReferences in)
(conj acc (.getName in)) (conj acc (.getName in))
(into acc (marker-names in)))) (into acc (get-marker-names in))))
acc (.iterator m)))) acc (.iterator m))))
;; Vector of markers ;; Vector of markers
(reduce (reduce
(fn [acc in] (into acc (marker-names in))) (fn [acc in] (into acc (get-marker-names in)))
#{} (truss/have vector? marker-or-markers)))))) #{} (truss/have vector? marker-or-markers))))))
(comment (comment
@ -97,9 +97,9 @@
ms [m1 m2]] ms [m1 m2]]
(enc/qb 1e6 ; [45.52 47.48 44.85] (enc/qb 1e6 ; [45.52 47.48 44.85]
(marker-names m1) (get-marker-names m1)
(marker-names cm) (get-marker-names cm)
(marker-names ms)))) (get-marker-names ms))))
;;;; Interop fns (called by `TelemereLogger`) ;;;; Interop fns (called by `TelemereLogger`)
@ -132,11 +132,10 @@
(org.slf4j.helpers.MessageFormatter/basicArrayFormat (org.slf4j.helpers.MessageFormatter/basicArrayFormat
msg-pattern args)) msg-pattern args))
:data :slf4j/args args ; Object[]
(enc/assoc-some nil :slf4j/markers marker-names ; Usu. used for routing, filtering, xfns, etc.
:slf4j/marker-names marker-names :data (when kvs {:slf4j/kvs kvs})})
:slf4j/args (when args (vec args))
:slf4j/kvs kvs)})
nil) nil)
(defn- log! (defn- log!
@ -149,7 +148,7 @@
error (.getThrowable event) error (.getThrowable event)
msg-pattern (.getMessage event) msg-pattern (.getMessage event)
args (when-let [args (.getArgumentArray event)] args) args (when-let [args (.getArgumentArray event)] args)
markers (when-let [markers (.getMarkers event)] (marker-names (vec markers))) marker-names (when-let [markers (.getMarkers event)] (get-marker-names (vec markers)))
kvs (when-let [kvps (.getKeyValuePairs event)] kvs (when-let [kvps (.getKeyValuePairs event)]
(reduce (reduce
(fn [acc ^org.slf4j.event.KeyValuePair kvp] (fn [acc ^org.slf4j.event.KeyValuePair kvp]
@ -157,11 +156,11 @@
nil kvps))] nil kvps))]
(when-debug (println [:slf4j/fluent-log-call (sig-level level) logger-name])) (when-debug (println [:slf4j/fluent-log-call (sig-level level) logger-name]))
(normalized-log! logger-name level inst error msg-pattern args markers kvs))) (normalized-log! logger-name level inst error msg-pattern args marker-names kvs)))
;; Legacy API calls ;; Legacy API calls
([logger-name ^org.slf4j.event.Level level error msg-pattern args marker] ([logger-name ^org.slf4j.event.Level level error msg-pattern args marker]
(let [marker-names (when marker (marker-names marker))] (let [marker-names (when marker (get-marker-names marker))]
(when-debug (println [:slf4j/legacy-log-call (sig-level level) logger-name])) (when-debug (println [:slf4j/legacy-log-call (sig-level level) logger-name]))
(normalized-log! logger-name level (enc/now-inst*) error msg-pattern args marker-names nil)))) (normalized-log! logger-name level (enc/now-inst*) error msg-pattern args marker-names nil))))