I'm trying to create a wrapper that extends tracing::error! by triggering additional side-effects when there is something wrong anywhere in the code, and I'm using this wrapper as a replacement for tracing::error!.
If I call tracing_error! from the wrapper, it will give me the location where I defined the wrapper rather than the location where there is something wrong in the code. I partly solved it by using this setting in tracing_subscriber configuration:
.with(fmt::layer().without_time())`
The above reduces some of the verbosity in the error log by turning off the displaying of the line number where I defined the wrapper. But the filename of the wrapper is still being displayed. It now looks something like this:
tracing::error is a macro with very complex parsing rules, it is very hard to create a wrapper macro that is robust and can replace it. besides, the tracing::error macro is not the only way to record an "ERROR"-level event (e.g. using the tracing::event macro, or using the Dispatch::event() method directly), so you are not guaranteed to catch all the events by just replacing the error macro anyway.
if you want to hook into every "ERROR" event, the "proper" way is to utilize the global (thread-local, to be precise) Subscriber: you can either define your own full-blown Subscriber, or you can define a single Layer (configured with a suitable Filter, e.g. LevelFilter::ERROR).
you will receive the information of the recorded event in the Subscriber::event() method or the Layer::on_event() method. but the Layer apprach is easier because you have less required methods to implement.
I tried defining my own Layer for the subscriber. For this, I need an Event to insert as argument in on_event() method so that I can run the desired side-effects in response to an error event.
I found only two method to create an Event: new() and new_child_of(). Both of these methods require ValueSet as argument.
So basically there seems to be a catch-22 between Attributes and ValueSet, and this catch-22 is a dependency of Event, which is a dependency of Layer::on_event().