-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add Log Events: A simple way to view tracing logs #10737
base: main
Are you sure you want to change the base?
Conversation
The generated |
I don't think logs should be forwarded as events Either you need events from some of the things that are logged, then add events at those points, or you need to process logs, then you should add a subscriber to tracing (#7682) |
I actually did have a nearly identical solution to #7682, but I ended scrapping it for 3 reasons:
|
I accidentally closed it, whoops. |
Instead of listening in via Bevy events, it may be better to use tracing's infrastructure (i.e. tracing_subscriber's |
I think this kind of feature would be useful to display error logs on screen such as with https://github.com/nicopap/bevy-debug-text-overlay/ |
@james7132 It should be possible to add additional layers by reinitializing the plug-in and all its layers. But, as I said earlier I don't see the benefit of creating your own layers for the reasons I already talked about above.
|
I'm also slightly concerned about performance issues, unless of course tracing (through the normal It would be great to be able to have some way of reading tracing events, maybe very intentionally feature flagging this on an opt-in basis for the And I'm probably naive, but what's stopping this from being implemented using |
Objective
Some plugins (such as my W.I.P.
bevy_dev_console
plugin) require access totracing
's logs (logs created withinfo!
,warn!
,error!
, etc.). However, it is quite difficult to accesstracing
's logs. You need to replace the defaultLogPlugin
with your own implementation that adds a customLayer
for handling logs.This PR adds a
LogMessage
event which makes gettingtracing
logs much easier.Solution
I created
LogEventLayer
, this is a struct that implementsLayer
and stores anArc<Mutex<Vec<LogMessage>>>
(which is shared with aLogEvents
resource). TheLogEventLayer
layer usesLogEventVisitor
to record the message string.LogEventLayer
pushes the message along with it's metadata to it'sArc<Mutex<Vec<LogMessage>>>
. Then a system calledtransfer_log_events
reads those log events with theLogEvents
resource and writes them toEvents<LogMessage>
viaEventWriter<LogEvent>
.This implementation isn't the best and it's quite long, but I'm not sure if there's a simpler way to transfer the log events from the
LogEventLayer
to theEvents<LogMessage>
. If you have an idea of how to simplify it that would be appreciated.I also added an example of how to use it.
Changelog