# 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 info("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 = "[color=gray](" + script + ") [DIAG] [b]" + preprocessor.pre(0,script,message) + "[/b][/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 = "(" + script + ") [INFO] [b]" + preprocessor.pre(1,script,message) + "[/b]" 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 = "[color=orange](" + script + ") [WARN] [b]" + preprocessor.pre(2,script,message) + "[/b][/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 = "[color=red](" + script + ") [ERROR] [b]" + preprocessor.pre(3,script,message) + "[/b][/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)