74 lines
2.3 KiB
GDScript3
74 lines
2.3 KiB
GDScript3
|
# 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:
|
||
|
var logmsg = "(" + script + ") [DIAG] " + preprocessor.pre(0,script,message)
|
||
|
print(logmsg)
|
||
|
emit_signal("logevent","DIAG",script,message,logmsg)
|
||
|
else:
|
||
|
var logmsg = "(" + script + ") [DIAG] " + message
|
||
|
print(logmsg)
|
||
|
emit_signal("logevent","DIAG",script,message,logmsg)
|
||
|
|
||
|
func info(script:String,message:String,preproc:bool = true) -> void:
|
||
|
if enable:
|
||
|
if preproc:
|
||
|
var logmsg = "(" + script + ") [INFO] " + preprocessor.pre(1,script,message)
|
||
|
print(logmsg)
|
||
|
emit_signal("logevent","INFO",script,message,logmsg)
|
||
|
else:
|
||
|
var logmsg = "(" + script + ") [INFO] " + message
|
||
|
print(logmsg)
|
||
|
emit_signal("logevent","INFO",script,message,logmsg)
|
||
|
|
||
|
func warn(script:String,message:String,preproc:bool = true) -> void:
|
||
|
if enable:
|
||
|
if preproc:
|
||
|
var logmsg = "(" + script + ") [WARN] " + preprocessor.pre(2,script,message)
|
||
|
print(logmsg)
|
||
|
emit_signal("logevent","WARN",script,message,logmsg)
|
||
|
else:
|
||
|
var logmsg = "(" + script + ") [WARN] " + message
|
||
|
print(logmsg)
|
||
|
emit_signal("logevent","WARN",script,message,logmsg)
|
||
|
|
||
|
func error(script:String,message:String,preproc:bool = true) -> void:
|
||
|
if enable:
|
||
|
if preproc:
|
||
|
var logmsg = "(" + script + ") [ERROR] " + preprocessor.pre(3,script,message)
|
||
|
print(logmsg)
|
||
|
emit_signal("logevent","ERROR",script,message,logmsg)
|
||
|
else:
|
||
|
var logmsg = "(" + script + ") [ERROR] " + message
|
||
|
print(logmsg)
|
||
|
emit_signal("logevent","ERROR",script,message,logmsg)
|