Fork me on GitHub
#timbre
<
2022-01-13
>
Richard Gebbia22:01:40

Hi there. I appear to be losing my timbre logging context inside a manifold chain fn, which I believe is executed in a separate thread. Any idea how I might keep that logging context so that I can log inside these fns?

tanzoniteblack22:01:26

use bound-fn instead of fn

tanzoniteblack22:01:40

the logging context is a dynamic bound variable, which is a thread local binding. when you do chain, it will kick off the function on a different thread & you’ll lose any thread local bindings. bound-fn will create the fn and preserve those

tanzoniteblack22:01:11

personally, for most use cases, I recommend simply using the go-off macro instead of directly using chain. It automatically keeps thread local bindings so you don’t have to worry about it yourself see https://github.com/clj-commons/manifold/blob/master/doc/deferred.md#go-off