Skip to content

bevy_log: refactor how log layers are wired together #19248

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

Merged

Conversation

SilentSpaceTraveller
Copy link
Contributor

@SilentSpaceTraveller SilentSpaceTraveller commented May 17, 2025

Objective

Current way to wire Layers together using layer.with(new_layer) in the bevy_log plugin is brittle and not flexible. As #17722 demonstrated, the current solution makes it very hard to do any kind of advanced wiring, as the type system of tracing::Subscriber gets in the way very quickly (the type of each new layer depends on the type of the previous ones). We want to make it easier to have more complex wiring of Layers. It would be hard to solve #19085 without it

Solution

It aims to be functionally equivalent.

Testing

  • Ran CI locally on Linux
  • Ran the logs examples
  • Need people familiar with the features trace, tracing-chrome, tracing-tracy to check that it still works as expected
  • Need people with access to ios, android and wasm to check it as well.

@SilentSpaceTraveller
Copy link
Contributor Author

SilentSpaceTraveller commented May 17, 2025

No idea how to fix CI / miri. I looked at the error, but it isn't really helpful to explain why my change made it fail. I am a new contributor to bevy, so if someone has some insight on how to do that, I'd be happy to learn.

Edit: It was due to CI failing not my PR, so all good now

@janhohenheim janhohenheim added S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Diagnostics Logging, crash handling, error reporting and performance analysis S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 17, 2025
@SilentSpaceTraveller
Copy link
Contributor Author

I couldn't get this to work in a generic way, but if anyone can, I'd love to swap this out for something more maintainable (these type aliases would break if we changed ordering of existing layers or add additional layers).

Originally posted by @JeanMertz in #17722 (comment)

@JeanMertz, you might have a look at the solution I propose in this PR to solve that issue

Copy link
Contributor

@JeanMertz JeanMertz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it. I missed that part of the tracing document, and this is indeed a much cleaner implementation.

@BenjaminBrienen BenjaminBrienen added C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jun 16, 2025
@alice-i-cecile alice-i-cecile added D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes and removed D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jun 16, 2025
@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Jun 16, 2025

#[expect(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which variable isn't used? Can't you just cfg it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom_format_layer is not used when compiling for wasm32, android or ios.
As it is passed as an argument to the function, not possible to cfg that to my knowledge (function signature would change otherwise)

Copy link
Contributor Author

@SilentSpaceTraveller SilentSpaceTraveller Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was already #19085 that tracks the fact that the way we configure things with custom_format_layer is not optimal. I tried to keep the scope focused and manageable for this refactor in order to not change the way users need to configure things.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom_format_layer is not used when compiling for wasm32, android or ios. As it is passed as an argument to the function, not possible to cfg that to my knowledge (function signature would change otherwise)

You can config a parameter out. There's no reason to make those platforms pass that parameter in, right?

Copy link
Contributor

@kristoff3r kristoff3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really nice cleanup!

I tested it with tracing-wasm (working around the issue in tokio-rs/tracing#2720 by not printing time) and tracing-chrome, both work as expected.

@kristoff3r kristoff3r added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 16, 2025
Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so much nicer than what we had before!

Co-authored-by: Kristoffer Søholm <k.soeholm@gmail.com>
@alice-i-cecile alice-i-cecile enabled auto-merge June 16, 2025 21:12
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 16, 2025
Merged via the queue into bevyengine:main with commit 8661e91 Jun 16, 2025
32 checks passed
@JMS55
Copy link
Contributor

JMS55 commented Jun 17, 2025

I think this broke our default log filters. All the examples are now dumping every shader to stdout.

@IceSentry
Copy link
Contributor

Yeah, this PR broke log filtering. There's a bit more detail in this issue #19689

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants