Rework logging system a bit

This commit is contained in:
JeremyStar™ 2024-04-07 21:13:45 +02:00
parent b96812fbad
commit 46f83c8683
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -3,10 +3,11 @@ extends Control
# Configuration for the configuration
var config: Node = Node.new()
const config_path: String = "res://addons/besseretests_config.gd"
const config_keys: Dictionary = { "test_directory": TYPE_STRING, "print_orphan_nodes": TYPE_BOOL }
const config_keys: Dictionary = { "test_directory": TYPE_STRING, "loglevel": TYPE_INT, "print_orphan_nodes": TYPE_BOOL }
# Configuration
var config_test_directory: String = "res://tests"
var config_loglevel: int = 2
var config_print_orphan_nodes: bool = false
# Statistics <3 & results
@ -112,6 +113,7 @@ func _ready() -> void:
# Runs a test suite
func run_suite(suite: String) -> void:
linfo("Running suite \"" + suite + "\"")
# Load test suite
var suite_node: BessereTestsTest = BessereTestsTest.new()
suite_node.set_script(load(config_test_directory + "/" + suite + ".gd"))
@ -162,12 +164,33 @@ func run_suite(suite: String) -> void:
suite_node.queue_free()
# Logging
func _log(message: String, origin: String, level: int) -> void:
if level >= config_loglevel:
var level_name: String
var level_color: String
match(level):
0:
level_name = "DIAG"
level_color = "gray"
1:
level_name = "VERB"
level_color = "gray"
2:
level_name = "INFO"
level_color = "white"
3:
level_name = "WARN"
level_color = "yellow"
4:
level_name = "ERR!"
level_color = "red"
print_rich("[color=" + level_color + "]" + level_name + " " + origin + ": " + message.replace("\n", "\\n") + "[/color]")
func lresu(message: String, origin: String = "Bessere Tests") -> void: print_rich("[color=white]RESU " + origin + ": " + message + "[/color]")
func ldiag(message: String, origin: String = "Bessere Tests") -> void: print_rich("[color=gray]DIAG " + origin + ": " + message + "[/color]")
func lverb(message: String, origin: String = "Bessere Tests") -> void: print_rich("[color=gray]VERB " + origin + ": " + message + "[/color]")
func linfo(message: String, origin: String = "Bessere Tests") -> void: print_rich("[color=white]INFO " + origin + ": " + message + "[/color]")
func lwarn(message: String, origin: String = "Bessere Tests") -> void: print_rich("[color=yellow]WARN " + origin + ": " + message + "[/color]")
func lerror(message: String, origin: String = "Bessere Tests") -> void: print_rich("[color=red]ERR! " + origin + ": " + message + "[/color]")
func ldiag(message: String, origin: String = "Bessere Tests") -> void: _log(message, origin, 0)
func lverb(message: String, origin: String = "Bessere Tests") -> void: _log(message, origin, 1)
func linfo(message: String, origin: String = "Bessere Tests") -> void: _log(message, origin, 2)
func lwarn(message: String, origin: String = "Bessere Tests") -> void: _log(message, origin, 3)
func lerror(message: String, origin: String = "Bessere Tests") -> void: _log(message, origin, 4)
func lcrash(message: String, origin: String = "Bessere Tests") -> void:
crashed = true
print_rich("[color=red][b]CRSH " + origin + ": " + message + "[/b][/color]")