CORE/logger.gd
JeremyStarTM 99703cf03e CORE rewrite (#1)
Reviewed-on: StarOpenSource/core#1

Rewrote CORE and improved the startup process and startup time significantly. The documentation has been beefed up too and is now much better. Existing projects may need major refactoring however.
Co-authored-by: JeremyStarTM <jeremystartm@staropensource.de>
Co-committed-by: JeremyStarTM <jeremystartm@staropensource.de>
2023-08-25 14:34:57 +02:00

118 lines
4.8 KiB
GDScript

######################################
# 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
# 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
# Signals
signal logevent
func initialize() -> void:
if core.protection_mode: return
if preprocessor == null:
return
diag("CORE/logger.gd","Logger is ready.")
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
print_rich(logmsg)
# Emit logevent signal
emit_signal("logevent","DIAG",script,message,logmsg)
else:
# 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
emit_signal("logevent","DIAG",script,message,logmsg)
func info(script:String,message:String,preproc:bool = true) -> void:
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
print_rich(logmsg)
# Emit logevent signal
emit_signal("logevent","INFO",script,message,logmsg)
else:
# 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
emit_signal("logevent","INFO",script,message,logmsg)
func warn(script:String,message:String,preproc:bool = true) -> void:
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
print_rich(logmsg)
# Emit logevent signal
emit_signal("logevent","WARN",script,message,logmsg)
else:
# 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
emit_signal("logevent","WARN",script,message,logmsg)
func error(script:String,message:String,preproc:bool = true) -> void:
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
print_rich(logmsg)
# Emit logevent signal
emit_signal("logevent","ERR!",script,message,logmsg)
else:
# 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)