bevy-console
bevy-console copied to clipboard
Is it possible to hook info! etc and send to the console?
I'd like to be able to pipe all the standard bevy output to the console. Is there a way to do that?
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:
- Author a Subscriber & Layer similar to tracing_subscriber::fmt which handles Records for the console.
- Modify Bevy to allow for third party layers prior to installation of the global default subscriber.
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?