Closed brandon-reinhart closed 1 day ago
Looks like it might be if Bevy provided a way to modify the tracing subscriber. At the moment, the only alternative is to provide a custom tracing subscriber.
It would be nice to have some sort of "hook" or multiple subscribers indeed
Some research here.
Bevy installs a tracing subscriber in bevy::log::LogPlugin. A tracing subscriber consists of layers, each of which get a chance to modify what is traced or how the trace is handled. Bevy's subscriber uses a fmt layer which outputs log Records to stdout. Bevy also uses LogTracer which directs log macros like info! to create tracing Records.
info! -> Record -> fmt Layer -> stdout
I believe tracing only supports one subscriber, so if you want to direct records to the console you need to install a layer. Once the subscriber is set, you can't add a new layer to it.
This means this task decomposes into:
I had a go at making bevy able to inject extra log layers: https://github.com/bevyengine/bevy/pull/7682
The PR has some issues, because plugin build
can't take ownership of their parameters at the moment.
The pr has an example which should get you pretty close to this however.
I'm not currently working on the PR, just thought I'd share if someone wants to pick it up.
While log layer support is being worked on, did anybody manage to redirect the regular println! stdout/stderr to the console?
FWIW, I think this is possible now.
I investigated this, looks like we're going to need a small adjustment that's in bevy main in order to direct custom subscriber events to the ECS. Then it will be easy to have a system that can scoop this into the console.
I wonder if we can do this with Bevy 0.14
I think it is, I got an example working with a custom layer and a buffer resource
Oooo... Do you think you could share the code for it?
Yeah, I will likely put up a PR today
I'd like to be able to pipe all the standard bevy output to the console. Is there a way to do that?