CORE/logger.gd
JeremyStarTM b57d00e9cd Many improvements (see commit description)
Added more things to roadmap, removed autoload singleton check, added support for Godot 4.1, all startup messages now use Logger.diag() instead of Logger.info() (making them disappear but can be shown if needed), removed autoload.gd, fixes syntax.
2023-07-07 10:58:49 +02:00

73 lines
2.8 KiB
GDScript

# logger.gd
# CORE Logger
#
# This file is part of StarOpenSource CORE (SOSCORE)
# Made by the StarOpenSource Project and Contributers
# Licensed under GNU GPLv3
extends Control
signal logevent
@onready
var preprocessor = get_node(NodePath("/root/Preprocessor"))
@export
@export_category("Configuration")
# Enables/disables logging
var enable = true
@export
@export_category("Configuration")
# Enables/disables diagnostic/verbose logging
var enable_diag = false
# Initializes the
func _ready() -> void:
print("logger -> Initializing Logger")
if get_node_or_null(NodePath("/root/Preprocessor")) == null:
print("logger -> Preprocessor is not loaded. Shutting application down...")
get_tree().quit(1)
await get_tree().create_timer(1).timeout
diag("Logger","Logger is ready.")
func diag(script:String,message:String,preproc:bool = false) -> void:
if enable and enable_diag:
if preproc and Preprocessor.enabled:
var logmsg = preprocessor.process(message,"[color=gray](" + script + ") [DIAG] [/color]","[color=gray][b]","[/b][/color]",["[color=gray]","[/color]"])
print_rich(logmsg)
emit_signal("logevent","DIAG",script,message,logmsg)
else:
var logmsg = "[color=gray](" + script + ") [DIAG] [b]" + message + "[/b][/color]"
print_rich(logmsg)
emit_signal("logevent","DIAG",script,message,logmsg)
func info(script:String,message:String,preproc:bool = true) -> void:
if enable:
if preproc and Preprocessor.enabled:
var logmsg = preprocessor.process(message,"[color=white](" + script + ") [INFO] [/color]","[color=white][b]","[/b][/color]",["[color=white]","[/color]"])
print_rich(logmsg)
emit_signal("logevent","INFO",script,message,logmsg)
else:
var logmsg = "(" + script + ") [INFO] [b]" + message + "[/b]"
print_rich(logmsg)
emit_signal("logevent","INFO",script,message,logmsg)
func warn(script:String,message:String,preproc:bool = true) -> void:
if enable:
if preproc and Preprocessor.enabled:
var logmsg = preprocessor.process(message,"[color=orange](" + script + ") [WARN] [/color]","[color=orange][b]","[/b][/color]",["[color=orange]","[/color]"])
print_rich(logmsg)
emit_signal("logevent","WARN",script,message,logmsg)
else:
var logmsg = "[color=orange](" + script + ") [WARN] [b]" + message + "[/b][/color]"
print_rich(logmsg)
emit_signal("logevent","WARN",script,message,logmsg)
func error(script:String,message:String,preproc:bool = true) -> void:
if enable:
if preproc and Preprocessor.enabled:
var logmsg = preprocessor.process(message,"[color=red](" + script + ") [ERROR] [/color]","[color=red][b]","[/b][/color]",["[color=red]","[/color]"])
print_rich(logmsg)
emit_signal("logevent","ERROR",script,message,logmsg)
else:
var logmsg = "[color=red](" + script + ") [ERROR] [b]" + message + "[/b][/color]"
print_rich(logmsg)
emit_signal("logevent","ERROR",script,message,logmsg)