Skip to content

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Sep 5, 2025

This demo showcases a custom logger implementation, which runs in parallel to the built-in logging facilities (including file logging). The custom logger displays all messages printed by the engine in an in-game console.

Preview

custom_logging

@Calinou Calinou marked this pull request as draft September 5, 2025 16:49
@Calinou Calinou force-pushed the add-custom-logging-demo branch from 43816e7 to e8995bf Compare September 5, 2025 17:16
@Calinou Calinou force-pushed the add-custom-logging-demo branch from e8995bf to 240d505 Compare September 14, 2025 20:45
@Calinou Calinou marked this pull request as ready for review September 14, 2025 20:45
@mihe
Copy link
Contributor

mihe commented Sep 17, 2025

CustomLogger is not taking into account that _log_error and _log_message can be called from non-main threads (and multiple threads at the same time) so will most likely end up with a race condition when appending to the RichTextLabel, or perhaps tripping some thread guard error somewhere.

I guess deferring the append to the main thread would be the best option in this case, ideally with some comment explaining the thread-safety gotcha.

EDIT: It might be a good idea to add a OS.remove_logger call somewhere in there as well, just to show that it exists, since the user might "leak" stuff otherwise.

@Calinou
Copy link
Member Author

Calinou commented Sep 23, 2025

I guess deferring the append to the main thread would be the best option in this case

That makes sense, but I'm not sure how to do it in GDScript. Is it just a matter of using call_deferred()?

@mihe
Copy link
Contributor

mihe commented Sep 23, 2025

Is it just a matter of using call_deferred()?

Yep!

This demo showcases a custom logger implementation, which runs in parallel
to the built-in logging facilities (including file logging). The custom logger
displays all messages printed by the engine in an in-game console.
@Calinou Calinou force-pushed the add-custom-logging-demo branch from ab1f914 to fe5bba8 Compare September 24, 2025 19:55
@Calinou
Copy link
Member Author

Calinou commented Sep 24, 2025

call_deferred() is now used, and I've made use of OS.remove_logger() too. I've added a comment at the top of the CustomLogger class to emphasize the importance of thread safety.

@Calinou Calinou merged commit 9fb7d5d into godotengine:master Sep 26, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants