This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-30
Channels
- # admin-announcements (1)
- # adventofcode (2)
- # announcements (2)
- # babashka (60)
- # beginners (48)
- # cherry (1)
- # cider (16)
- # clj-kondo (4)
- # clojure (53)
- # clojure-belgium (3)
- # clojure-europe (20)
- # clojure-nl (1)
- # clojure-norway (6)
- # clojure-poland (4)
- # clojure-uk (6)
- # clojuredesign-podcast (19)
- # clojurescript (39)
- # community-development (12)
- # cursive (4)
- # datalevin (7)
- # datomic (23)
- # honeysql (14)
- # hyperfiddle (3)
- # instaparse (3)
- # lsp (3)
- # malli (10)
- # off-topic (34)
- # overtone (8)
- # polylith (2)
- # re-frame (9)
- # reitit (3)
- # releases (1)
- # squint (16)
- # timbre (7)
- # wasm (2)
- # xtdb (8)
Hhello
I have a problem rebinding out so it works inside a catch statement, using timbre. With println it works
the test program looks like this:
(require '[babashka.process :as p]
'[clojure.edn :as edn]
'[babashka.fs :as fs])
(require '[babashka.cli :as cli])
(require '[clojure.string :as str])
(require '[taoensso.timbre :as timbre])
(import 'java.time.format.DateTimeFormatter
'java.time.LocalDateTime)
(def ^:dynamic *foo* "foo root value")
(defn clone-and-build-repo []
(println "(stdout) start, nothing should go to stdout")
(let [writer ( "/tmp/bindproblem.txt")]
(with-open [out-writer writer]
(binding [*out* out-writer
*foo* "foo inside binding"]
(timbre/info "out:" *out*)
(timbre/info "foo inside binding:" *foo*)
(try
(timbre/info "this should go to the file " )
(println "this too")
(throw (new Exception "an error im trhowing"))
(catch Exception e
;;*out* seems to revert to default value here?
(binding [*out* out-writer]
(timbre/info "foo inside catch:" *foo*)
(timbre/info "out:" *out*)
(timbre/error e " not going to the file? it should!" ))
)))))
(println "(stdout) ... until now")
(println "(stdout) start file content")
(println (slurp "/tmp/bindproblem.txt"))
(println "(stdout) end file content")
)
( clone-and-build-repo)
Hi Joakim,
From skimming your example code, my guess is that timbre/error
may be printing to *err*
when you’re logging an error. Depends on your appender though, and it wasn’t obvious to me from your example if only the error
call is producing unexpected output or not.
I’d try binding both *out*
and *err*
and see if that helps. BTW if it does help, you shouldn’t need to rebind again in the catch
block.
Some general feedback-
• Please try strip unnecessary/irrelevant code in examples to make them easier to read.
• Please consider including relevant info when possible (e.g. here what appender/s you’re using, which log calls are/not producing expected output, etc.).
These kinds of things can make it easier for maintainers or other users to assist, which means you’re likely to get useful help sooner.
Hope that helps, cheers! 🙂
thanks!
You’re welcome, cheers!
the output inside the catch should also go to the file, instead it goes to stdout