Skip to content

gg.print() for printing log messages with clickable links back to the source script

License

Notifications You must be signed in to change notification settings

graydoubt/gg_print

Repository files navigation

gg.print() - an experimental logger with links to the source

This little project was inspired by this reddit post asking if print messages can link back to the source script in the editor.

Since the Godot editor is powered by the Godot Engine, it's possible with an EditorPlugin.

The plugin does two things:

  1. Provide a "gg" singleton/autoload with a print() method that uses print_rich() to print messages with link that contain the stack trace (via get_stack()).
  2. Attach a "meta_clicked" signal handler to the EditorLog (the output panel), so that clicks on the link can be opened in the editor.

With that, it's possible to call:

gg.print("Clicking me links back to the source file.")

Demo

Run the main.tscn scene and click the buttons to see print messages in the output. Clicking the messages will take you to the script source where they were called.

Limitations

  • Since this is an editor plugin, it won't run for exported games, which means the gg autoload won't be available, which means errors. You'd have to either remove all the gg.print() calls, search and replace them all with a regular print() statement, or autoload a dummy script, so gg.print() is available.

  • gg.print() also only accepts a string, variadic functions are still in the proposal stage.

This is only a proof of concept.

Notes

EditorInterface helps when creating editor plugins, but I was surprised that there's no clean, good way to get access to any of the existing panels. You have to traverse the tree yourself, which feels a bit brittle. The EditorLog defines the node structure in the source.

About

gg.print() for printing log messages with clickable links back to the source script

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published