2023-08-25 14:34:57 +02:00
|
|
|
######################################
|
|
|
|
# THE CORE FRAMEWORK #
|
|
|
|
# MADE BY THE STAROPENSOURCE PROJECT #
|
|
|
|
# AND CONTRIBUTERS (THANK YOU!) #
|
|
|
|
# #
|
|
|
|
# COPYRIGHT 2023 THE STAROPENSOURCE #
|
|
|
|
# PROJECT AND CONTRIBUTERS #
|
|
|
|
# #
|
|
|
|
# LICENSED UNDER THE GNU GENERAL #
|
|
|
|
# PUBLIC LICENSE VERSION 3 (ONLY) #
|
|
|
|
######################################
|
|
|
|
extends Node
|
2023-03-18 16:34:12 +01:00
|
|
|
|
2023-08-25 14:34:57 +02:00
|
|
|
# CORE modules
|
|
|
|
var core: Node = null
|
|
|
|
var preprocessor: Node = null
|
|
|
|
|
|
|
|
# Enables/disables the logger
|
|
|
|
var enabled: bool = true
|
|
|
|
# Enables/disables diagnostic log messages
|
|
|
|
var diagnostic: bool = false
|
2023-03-18 16:34:12 +01:00
|
|
|
|
2023-08-25 14:34:57 +02:00
|
|
|
# Signals
|
|
|
|
signal logevent
|
2023-03-18 16:34:12 +01:00
|
|
|
|
2023-08-25 14:34:57 +02:00
|
|
|
func initialize() -> void:
|
|
|
|
if core.protection_mode: return
|
|
|
|
if preprocessor == null:
|
|
|
|
return
|
|
|
|
diag("CORE/logger.gd","Logger is ready.")
|
2023-03-18 16:34:12 +01:00
|
|
|
|
2023-08-25 14:34:57 +02:00
|
|
|
func diag(script:String,message:String,preproc:bool = true) -> void:
|
|
|
|
if core.protection_mode: return
|
|
|
|
# Check if both the logger and diagnostic log messages are enabled
|
|
|
|
if enabled and diagnostic:
|
|
|
|
# Check if preprocessing is allowed for this message and if the preprocessor is enabled
|
|
|
|
if preproc and preprocessor.enabled:
|
|
|
|
# Run the message through the preprocessor if enabled/allowed
|
|
|
|
var logmsg: String = preprocessor.process(message,"[color=gray](" + script + ") [DIAG] [/color]","[color=gray][b]","[/b][/color]",["[color=gray]","[/color]"])
|
|
|
|
# Print the message
|
2023-06-29 19:36:14 +02:00
|
|
|
print_rich(logmsg)
|
2023-08-25 14:34:57 +02:00
|
|
|
# Emit logevent signal
|
2023-03-18 16:34:12 +01:00
|
|
|
emit_signal("logevent","DIAG",script,message,logmsg)
|
|
|
|
else:
|
2023-08-25 14:34:57 +02:00
|
|
|
# Construct a log message normally if preprocessor is disabled/disallowed
|
|
|
|
# Note: We do not include bold and color tags in here because they can mess
|
|
|
|
# up the log messages in some cases
|
|
|
|
var logmsg: String = "(" + script + ") [DIAG] " + message
|
|
|
|
# Print the message
|
|
|
|
print(logmsg)
|
|
|
|
# Emit logevent signal
|
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:
|
2023-08-25 14:34:57 +02:00
|
|
|
if core.protection_mode: return
|
|
|
|
# Check if the logger is enabled
|
|
|
|
if enabled:
|
|
|
|
# Check if preprocessing is allowed for this message and if the preprocessor is enabled
|
|
|
|
if preproc and preprocessor.enabled:
|
|
|
|
# Run the message through the preprocessor if enabled/allowed
|
|
|
|
var logmsg: String = preprocessor.process(message,"[color=white](" + script + ") [INFO] [/color]","[color=white][b]","[/b][/color]",["[color=white]","[/color]"])
|
|
|
|
# Print the message
|
2023-06-29 19:36:14 +02:00
|
|
|
print_rich(logmsg)
|
2023-08-25 14:34:57 +02:00
|
|
|
# Emit logevent signal
|
2023-03-18 16:34:12 +01:00
|
|
|
emit_signal("logevent","INFO",script,message,logmsg)
|
|
|
|
else:
|
2023-08-25 14:34:57 +02:00
|
|
|
# Construct a log message normally if preprocessor is disabled/disallowed
|
|
|
|
# Note: We do not include bold and color tags in here because they can mess
|
|
|
|
# up the log messages in some cases
|
|
|
|
var logmsg: String = "(" + script + ") [INFO] " + message
|
|
|
|
# Print the message
|
|
|
|
print(logmsg)
|
|
|
|
# Emit logevent signal
|
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:
|
2023-08-25 14:34:57 +02:00
|
|
|
if core.protection_mode: return
|
|
|
|
# Check if the logger is enabled
|
|
|
|
if enabled:
|
|
|
|
# Check if preprocessing is allowed for this message and if the preprocessor is enabled
|
|
|
|
if preproc and preprocessor.enabled:
|
|
|
|
# Run the message through the preprocessor if enabled/allowed
|
|
|
|
var logmsg: String = preprocessor.process(message,"[color=orange](" + script + ") [WARN] [/color]","[color=orange][b]","[/b][/color]",["[color=orange]","[/color]"])
|
|
|
|
# Print the message
|
2023-06-29 19:36:14 +02:00
|
|
|
print_rich(logmsg)
|
2023-08-25 14:34:57 +02:00
|
|
|
# Emit logevent signal
|
2023-03-18 16:34:12 +01:00
|
|
|
emit_signal("logevent","WARN",script,message,logmsg)
|
|
|
|
else:
|
2023-08-25 14:34:57 +02:00
|
|
|
# Construct a log message normally if preprocessor is disabled/disallowed
|
|
|
|
# Note: We do not include bold and color tags in here because they can mess
|
|
|
|
# up the log messages in some cases
|
|
|
|
var logmsg: String = "(" + script + ") [WARN] " + message
|
|
|
|
# Print the message
|
|
|
|
print(logmsg)
|
|
|
|
# Emit logevent signal
|
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:
|
2023-08-25 14:34:57 +02:00
|
|
|
if core.protection_mode: return
|
|
|
|
# Check if the logger is enabled
|
|
|
|
if enabled:
|
|
|
|
# Check if preprocessing is allowed for this message and if the preprocessor is enabled
|
|
|
|
if preproc and preprocessor.enabled:
|
|
|
|
# Run the message through the preprocessor if enabled/allowed
|
|
|
|
var logmsg: String = preprocessor.process(message,"[color=red](" + script + ") [ERR!] [/color]","[color=red][b]","[/b][/color]",["[color=red]","[/color]"])
|
|
|
|
# Print the message
|
2023-06-29 19:36:14 +02:00
|
|
|
print_rich(logmsg)
|
2023-08-25 14:34:57 +02:00
|
|
|
# Emit logevent signal
|
|
|
|
emit_signal("logevent","ERR!",script,message,logmsg)
|
2023-03-18 16:34:12 +01:00
|
|
|
else:
|
2023-08-25 14:34:57 +02:00
|
|
|
# Construct a log message normally if preprocessor is disabled/disallowed
|
|
|
|
# Note: We do not include bold and color tags in here because they can mess
|
|
|
|
# up the log messages in some cases
|
|
|
|
var logmsg: String = "(" + script + ") [ERR!] " + message
|
|
|
|
# Print the message
|
|
|
|
print(logmsg)
|
|
|
|
# Emit logevent signal
|
|
|
|
emit_signal("logevent","ERR!",script,message,logmsg)
|