Debugging with a log file

So I went ahead and produced an Autoload scene that pops up a panel to facilitate logging of how the block code is executed.

Logger Popup

Attached logging script:

extends Node

var thelog: PoolStringArray

func _ready():
	$Popup.show()

func add(items: Array):
	var txt = "%-26s" % items[0]
	for i in items.size():
		if i > 0:
			txt += "%-12s" % items[i]
	thelog.append(txt)

func output():
	print(thelog.join("\n"))

func clear():
	thelog.resize(0)

func save():
	var fn = "../data/log.txt"
	var file = File.new()
	file.open(fn, File.WRITE)
	file.store_string(thelog.join("\n"))
	file.close()

func _on_Clear_pressed():
	clear()

func _on_Print_pressed():
	output()

func _on_Save_pressed():
	save()

In the code header I add var tracker = true and in various functions that I want to track, I add code such as:

if trace: Logger.add(["update_internal_bus", node.name, value, port])

Then we can obtain a log file such as this:

Logger Popup

This lists the function name, part name, input value, and port in order of being accessed.

This extremely useful information allowed me to easily locate the point of an unexpected value being produced and then locating the source of a bug.

More Devlog entries

Most recent first