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
|
|
|
|
info("Logger","Logger is ready.")
|
|
|
|
|
|
|
|
func diag(script:String,message:String,preproc:bool = false) -> void:
|
|
|
|
if enable and enable_diag:
|
|
|
|
if preproc:
|
2023-06-29 19:38:43 +02:00
|
|
|
var logmsg = "[gray](" + script + ") [DIAG] [b]" + preprocessor.pre(0,script,message) + "[/b][/gray]"
|
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:38:43 +02:00
|
|
|
var logmsg = "[gray](" + script + ") [DIAG] [b]" + message + "[/b][/gray]"
|
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:
|
2023-06-29 19:36:14 +02:00
|
|
|
var logmsg = "(" + script + ") [INFO] [b]" + preprocessor.pre(1,script,message) + "[/b]"
|
|
|
|
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:
|
2023-06-29 19:38:43 +02:00
|
|
|
var logmsg = "[orange](" + script + ") [WARN] [b]" + preprocessor.pre(2,script,message) + "[/b][/orange]"
|
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:38:43 +02:00
|
|
|
var logmsg = "[orange](" + script + ") [WARN] [b]" + message + "[/b][/orange]"
|
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:
|
2023-06-29 19:38:43 +02:00
|
|
|
var logmsg = "[red](" + script + ") [ERROR] [b]" + preprocessor.pre(3,script,message) + "[/b][/red]"
|
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:38:43 +02:00
|
|
|
var logmsg = "[red](" + script + ") [ERROR] [b]" + message + "[/b][/red]"
|
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)
|