Add Log Events: A simple way to view tracing logs#10737
Add Log Events: A simple way to view tracing logs#10737doonv wants to merge 11 commits intobevyengine:mainfrom
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 |
|
Triage: has merge conflicts |
Objective
Some plugins (such as my W.I.P.
bevy_dev_consoleplugin) 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 defaultLogPluginwith your own implementation that adds a customLayerfor handling logs.This PR adds a
LogMessageevent which makes gettingtracinglogs much easier.Solution
I created
LogEventLayer, this is a struct that implementsLayerand stores anArc<Mutex<Vec<LogMessage>>>(which is shared with aLogEventsresource). TheLogEventLayerlayer usesLogEventVisitorto record the message string.LogEventLayerpushes the message along with it's metadata to it'sArc<Mutex<Vec<LogMessage>>>. Then a system calledtransfer_log_eventsreads those log events with theLogEventsresource 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
LogEventLayerto 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