RichoDemus / bevy-console

MIT License
272 stars 59 forks source link

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

Closed brandon-reinhart closed 1 day ago

brandon-reinhart commented 2 years ago

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 commented 2 years 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.

makspll commented 2 years ago

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

brandon-reinhart commented 1 year ago

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:

johanhelsing commented 1 year ago

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.

sbaranov commented 1 year ago

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

brandon-reinhart commented 6 months ago

FWIW, I think this is possible now.

brandon-reinhart commented 6 months ago

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.

makspll commented 3 days ago

I wonder if we can do this with Bevy 0.14

makspll commented 3 days ago

I think it is, I got an example working with a custom layer and a buffer resource

makspll commented 3 days ago

image

johanhelsing commented 3 days ago

Oooo... Do you think you could share the code for it?

makspll commented 3 days ago

Yeah, I will likely put up a PR today