Skip to content

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Sep 9, 2025

This also covers how to create custom loggers.

@Calinou Calinou added content:new page Issues and PRs related to creation of new documentation pages for new or undocumented features area:manual Issues and PRs related to the Manual/Tutorials section of the documentation labels Sep 9, 2025
@Calinou Calinou force-pushed the add-logging branch 2 times, most recently from 7a1c1d3 to 7af417b Compare September 9, 2025 16:28
Comment on lines +199 to +248
.. code-block:: gdscript
extends Node
class CustomLogger extends Logger:
# Note that this method is not called for messages that use
# `push_error()` and `push_warning()`, even though these are printed to stderr.
func _log_message(message: String, error: bool) -> void:
# Do something with `message`.
# `error` is `true` for messages printed to the standard error stream (stderr) with `print_error()`.
pass
func _log_error(
function: String,
file: String,
line: int,
code: String,
rationale: String,
editor_notify: bool,
error_type: int,
script_backtraces: Array[ScriptBacktrace]
) -> void:
# Do something with the error. The error text is in `rationale`.
# See the Logger class reference for details on other parameters.
pass
# Use `_init()` to initialize the logger as early as possible, which ensures that messages
# printed early are taken into account. However, even when using `_init()`, the engine's own
# initialization messages are not accessible.
func _init() -> void:
OS.add_logger(CustomLogger.new())
Copy link
Member Author

@Calinou Calinou Sep 9, 2025

Choose a reason for hiding this comment

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

Note that I've decided to add type hints for this code sample, as it's arguably easier to understand with type hints present (and this documentation is fairly advanced).

@Calinou Calinou force-pushed the add-logging branch 2 times, most recently from 521ada7 to 2053bd7 Compare September 9, 2025 17:13
@Calinou Calinou force-pushed the add-logging branch 4 times, most recently from 3e99080 to 73e4e02 Compare September 9, 2025 21:26
@mhilbrunner mhilbrunner added this to the 4.5 milestone Sep 10, 2025
@skyace65 skyace65 added the linked demo pr Documentation PRs that are tied to a demo repository PR label Sep 11, 2025
This also covers how to create custom loggers.

- Remove notice on Windows 10 requirement for `print_rich()` in Output panel,
  since Godot requires Windows 10 as of 4.5.
@mhilbrunner mhilbrunner merged commit 8ad6d1c into godotengine:master Sep 14, 2025
1 check passed
@mhilbrunner
Copy link
Member

Thanks! Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation cherrypick:4.5 content:new page Issues and PRs related to creation of new documentation pages for new or undocumented features linked demo pr Documentation PRs that are tied to a demo repository PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants