CORE/logger.gd

74 lines
2.8 KiB
GDScript3
Raw Normal View History

2023-03-18 16:34:12 +01:00
# 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.")
2023-03-18 16:34:12 +01:00
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]"])
2023-06-29 19:36:14 +02:00
print_rich(logmsg)
2023-03-18 16:34:12 +01:00
emit_signal("logevent","DIAG",script,message,logmsg)
else:
2023-06-29 19:48:05 +02:00
var logmsg = "[color=gray](" + script + ") [DIAG] [b]" + message + "[/b][/color]"
2023-06-29 19:36:14 +02:00
print_rich(logmsg)
2023-03-18 16:34:12 +01:00
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]"])
2023-06-29 19:36:14 +02:00
print_rich(logmsg)
2023-03-18 16:34:12 +01:00
emit_signal("logevent","INFO",script,message,logmsg)
else:
2023-06-29 19:36:14 +02:00
var logmsg = "(" + script + ") [INFO] [b]" + message + "[/b]"
print_rich(logmsg)
2023-03-18 16:34:12 +01:00
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]"])
2023-06-29 19:36:14 +02:00
print_rich(logmsg)
2023-03-18 16:34:12 +01:00
emit_signal("logevent","WARN",script,message,logmsg)
else:
2023-06-29 19:48:05 +02:00
var logmsg = "[color=orange](" + script + ") [WARN] [b]" + message + "[/b][/color]"
2023-06-29 19:36:14 +02:00
print_rich(logmsg)
2023-03-18 16:34:12 +01:00
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]"])
2023-06-29 19:36:14 +02:00
print_rich(logmsg)
2023-03-18 16:34:12 +01:00
emit_signal("logevent","ERROR",script,message,logmsg)
else:
2023-06-29 19:48:05 +02:00
var logmsg = "[color=red](" + script + ") [ERROR] [b]" + message + "[/b][/color]"
2023-06-29 19:36:14 +02:00
print_rich(logmsg)
2023-03-18 16:34:12 +01:00
emit_signal("logevent","ERROR",script,message,logmsg)