Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brandon-reinhart opened this issue Jul 21, 2022 · 12 comments
Closed

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

brandon-reinhart opened this issue Jul 21, 2022 · 12 comments

Comments

@brandon-reinhart
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Collaborator

makspll commented Aug 10, 2022

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

@brandon-reinhart
Copy link
Collaborator Author

brandon-reinhart commented Sep 29, 2022

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.

@johanhelsing
Copy link
Contributor

I had a go at making bevy able to inject extra log layers: bevyengine/bevy#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
Copy link

sbaranov commented Apr 19, 2023

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

@brandon-reinhart
Copy link
Collaborator Author

FWIW, I think this is possible now.

@brandon-reinhart
Copy link
Collaborator Author

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
Copy link
Collaborator

makspll commented Sep 4, 2024

I wonder if we can do this with Bevy 0.14

@makspll
Copy link
Collaborator

makspll commented Sep 4, 2024

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

@makspll
Copy link
Collaborator

makspll commented Sep 4, 2024

image

@johanhelsing
Copy link
Contributor

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

@makspll
Copy link
Collaborator

makspll commented Sep 5, 2024

Yeah, I will likely put up a PR today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants