Open jsimonrichard opened 1 month ago
I would also really like this, my use case is turning some errors into panics during tests.
Hmm AFAIK this is currently not possible. One workaround would be to use MakeWriter
and implement io::Write
. https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.Layer.html#method.with_writer
Feature Request
I'm new to this crate, to apologies if I'm missing something obvious. But here goes...
I want to create a custom
Layer
that uses the standardtracing_subscriber::fmt::format::Format
formatter.My plan was to implement
Layer::on_event
, which is provided aContext
. To use the formatter, it seems like I need aFmtContext
. However, I can't figure out how to create one of those from aContext
. In fact, I haven't found any public functions that returnFmtContext
.Crates
tracing-subscriber
Motivation
My particular use case is that I want to send backend logs to the fronted (like in tauri_plugin_log). Each time something is logged I need to call a custom function (which takes a string message input, among other things), but I don't want to write custom formatting for that string.
Proposal
In
tracing_subscriber::fmt::Layer
, the privatemake_ctx
function is used:I would like to create a similar function that creates a FmtContext. Maybe something like this:
Alternatives
I'm not sure. Maybe this could be a function on
FmtContext
? But I think making this a function onContext
makes it clear that this is a conversion fromContext
toFmtContext
which requires extra parameters (fmt_fields
andevents
).