This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-15
Channels
- # babashka (3)
- # beginners (28)
- # calva (8)
- # cider (16)
- # clj-on-windows (4)
- # clojure (69)
- # clojure-europe (29)
- # clojure-norway (42)
- # clojure-uk (4)
- # community-development (5)
- # conjure (3)
- # cursive (18)
- # datomic (68)
- # emacs (23)
- # events (1)
- # honeysql (7)
- # introduce-yourself (1)
- # jobs (1)
- # lsp (11)
- # music (1)
- # observability (3)
- # off-topic (35)
- # other-languages (33)
- # releases (1)
- # remote-jobs (2)
- # ring (18)
- # shadow-cljs (16)
- # timbre (5)
- # tools-deps (9)
Using the timbre 5.2 default println-appender
Not entirely sure this is timbre specific or just me misunderstanding something unrelated
I am starting up a system that asynchrounously causes a lot of timbre debug
statements to be issued.
My println appender is created using (timbre/println-appender {:stream :auto})
.
During this I also need to prompt the user and read-line
a response.
I'd like for nothing to be logged or printed anywhere between when the prompt is printed and read-line occurs.
I'm attempting to accomplish this by using the following for my prompting code
(locking *out*
(print "Answer:")
(flush)
(read-line))
But I'm always getting this line printed as my prompt:
Answer: 24-05-15 14:38:47.267 DEBUG [my.ns:27] - My log msg
There's always some log message printed from some async process that occurs around the same time
Is there a way to ensure this doesn't happen?Hmm I wonder if this is because I'm using a remote clojure socket repl so my *out*
isn't the same object timbre is using so the locking
wont work as intended
Hi there!
> I’m attempting to accomplish this by using the following for my prompting code
Just to confirm- you’re really happy to literally cause all your application-wide logging calls on any thread to hard lock on this read-line
completing?
> Hmm I wonder if this is because I’m using a remote clojure socket repl so my *out*
isn’t the same object timbre is using so the locking
wont work as intended
That’s a reasonable thought to check, but more fundamentally- Timbre’s println appender doesn’t itself lock on *out*
. So even if you ensured that you had the same *out*
in both cases - Timbre’s println appender won’t care if something is locking *out*
.
Does that make sense?
> Is there a way to ensure this doesn’t happen?
TBH I’m a little skeptical of the idea of blocking all your logging for a read-line to finish, but I guess that might make sense in your context. If you want to try this, the simplest thing would probably be to write your own println
appender that uses the same lock.
You can use the https://github.com/taoensso/timbre/blob/10f7b0436e46ed9af1f83f0a5fad43f4bd317e9d/src/taoensso/timbre/appenders/core.cljc#L38 as a starting point.
Hope that helps?
Hmm good points
I definitely confused myself about how locking
works, and you're right that I shouldn't want to block all logging, though it might be fine in practice for this.
Probably a better approach is to either temporarily disable or buffer the println appender.
Definitely helpful starting points, thanks!
Re: ideal approach - much depends on the context of what you’re actually trying to do.
When waiting on the read-line
, is anything useful still going on in other/background threads? If not, you might be able to pause/lock your application logic (rather than just logging) while reading.
But if there is useful work going on in other/background threads, then an entirely different approach might make sense.
Best of luck!