Reading from Box not possible since fern::Output::writer consumes it?
Closed this issue · 2 comments
unixb0y commented
What I'm trying to do is logging into a Vec, which I can then process with my own code. I use Ratatui for my GUI and therefore I'd like an in-memory representation of my logs to show in one location.
I've been trying to get that to work starting from this example from the docs:
https://docs.rs/fern/latest/fern/struct.Output.html#method.writer
However, fern::Output::writer
consumes the Box, therefore I can't read back from it. Am I doing something wrong here? Is there a way to solve this?
piegamesde commented
Yes, that is by design. You cannot access the writer itself while fern is (potentially) writing to it. You may use one of the following solutions instead:
- Share your writer with the usual synchronization primitives (Rc/Refcell or Arc/Mutex)
- Use a channel
- Use a thread safe ring buffer
unixb0y commented
Alright, thanks!