bevy-console icon indicating copy to clipboard operation
bevy-console copied to clipboard

Is it possible to hook info! etc and send to the console?

Open brandon-reinhart opened this issue 3 years ago • 7 comments

I'd like to be able to pipe all the standard bevy output to the console. Is there a way to do that?

brandon-reinhart avatar Jul 21 '22 21:07 brandon-reinhart

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.

brandon-reinhart avatar Jul 29 '22 14:07 brandon-reinhart

It would be nice to have some sort of "hook" or multiple subscribers indeed

makspll avatar Aug 10 '22 17:08 makspll

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.

brandon-reinhart avatar Sep 29 '22 15:09 brandon-reinhart

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.

johanhelsing avatar Apr 10 '23 06:04 johanhelsing

While log layer support is being worked on, did anybody manage to redirect the regular println! stdout/stderr to the console?

sbaranov avatar Apr 19 '23 18:04 sbaranov