Sets up initial project structure
Initializes the project with core files including: - Editor configuration (.editorconfig, .gitattributes, .gitignore, .vscode/settings.json) - Log.gd addon for enhanced debugging - Loggie addon for advanced logging - Project assets folder
This commit is contained in:
parent
f8140c83ff
commit
02b3be35b0
144 changed files with 7399 additions and 0 deletions
28
addons/loggie/channels/custom_channels/template.gd.example
Normal file
28
addons/loggie/channels/custom_channels/template.gd.example
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
extends LoggieMsgChannel
|
||||
|
||||
func _init() -> void:
|
||||
self.ID = "<your-custom-id>"
|
||||
|
||||
# Example - Customize preprocess flags:
|
||||
# self.preprocess_flags = LoggieEnums.PreprocessStep.APPEND_TIMESTAMPS | LoggieEnums.PreprocessStep.APPEND_DOMAIN_NAME | LoggieEnums.PreprocessStep.APPEND_CLASS_NAME
|
||||
|
||||
func send(msg : LoggieMsg, msg_type : LoggieEnums.MsgType):
|
||||
# Validate that the message is coming from a valid logger if you are going to be requiring access to a [Loggie] instance.
|
||||
var loggie = msg.get_logger() # Access a [Loggie] instance directly from the message.
|
||||
if loggie == null:
|
||||
push_error("Attempt to send a message that's coming from an invalid logger.")
|
||||
return
|
||||
|
||||
# To access the most recently preprocessed version of the message - use:
|
||||
# msg.last_preprocess_result
|
||||
|
||||
# To access a string version of the message (no preprocessing) - use:
|
||||
var msg_text = msg.string()
|
||||
|
||||
# Optionally
|
||||
# We can use `LoggieTools.convert_string_to_format_mode` to apply one of the Loggie format modes to it.
|
||||
# Explore more functions in [LoggieTools] and [LoggieMsg].
|
||||
# var converted = LoggieTools.convert_string_to_format_mode(msg.last_preprocess_result, loggie.settings.msg_format_mode)
|
||||
|
||||
# Do something with the message.
|
||||
print(msg_text)
|
||||
75
addons/loggie/channels/discord.gd
Normal file
75
addons/loggie/channels/discord.gd
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
class_name DiscordLoggieMsgChannel extends LoggieMsgChannel
|
||||
|
||||
const discord_msg_character_limit = 2000 # The max. amount of characters the content of the message can contain before discord refuses to post it.
|
||||
var debug_domain = "_d_loggie_discord"
|
||||
var debug_enabled = false
|
||||
|
||||
func _init() -> void:
|
||||
self.ID = "discord"
|
||||
self.preprocess_flags = 0 # For this type of channel, this will be applied dynamically by Loggie after it loads LoggieSettings.
|
||||
|
||||
func send(msg : LoggieMsg, msg_type : LoggieEnums.MsgType):
|
||||
# Validate variables.
|
||||
var loggie = msg.get_logger()
|
||||
if loggie == null:
|
||||
push_error("Attempt to send a message that's coming from an invalid logger.")
|
||||
return
|
||||
|
||||
# Wait until loggie is inside tree so that we can use add_child(http) on it without errors.
|
||||
if !loggie.is_inside_tree():
|
||||
loggie.tree_entered.connect(func():
|
||||
send(msg, msg_type)
|
||||
, CONNECT_ONE_SHOT)
|
||||
return
|
||||
|
||||
var webhook_url = loggie.settings.discord_webhook_url_live if loggie.is_in_production() else loggie.settings.discord_webhook_url_dev
|
||||
if webhook_url == null or (webhook_url is String and webhook_url.is_empty()):
|
||||
push_error("Attempt to send a message to the Discord channel with an invalid webhook_url.")
|
||||
return
|
||||
|
||||
var output_text = LoggieTools.convert_string_to_format_mode(msg.last_preprocess_result, LoggieEnums.MsgFormatMode.MARKDOWN)
|
||||
|
||||
# Chunk the given string into chunks of maximum supported size by Discord, so we don't end up hitting the character limit
|
||||
# which would prevent the message from getting posted.
|
||||
var chunks = LoggieTools.chunk_string(output_text, discord_msg_character_limit)
|
||||
if chunks.size() > 1:
|
||||
loggie.debug("Chunking a long (", output_text.length(), "length ) message while sending to Discord into:", chunks.size(), "chunks.")
|
||||
for chunk : String in chunks:
|
||||
call_deferred("send_post_request", loggie, chunk, webhook_url)
|
||||
|
||||
func send_post_request(logger : Variant, output_text : String, webhook_url : String):
|
||||
# Enable debug messages if configured.
|
||||
logger.set_domain_enabled(debug_domain, debug_enabled)
|
||||
|
||||
# Create a new HTTPRequest POST request that will be sent to Discord and add it into the scenetree.
|
||||
var http = HTTPRequest.new()
|
||||
logger.add_child(http)
|
||||
|
||||
# When the request is completed, destroy it.
|
||||
http.request_completed.connect(func(result, response_code, headers, body):
|
||||
var debug_msg = logger.msg("HTTP Request Completed:").color(Color.ORANGE).header().domain(debug_domain).channel("terminal")
|
||||
debug_msg.nl().msg("Result:").color(Color.ORANGE).bold().space().msg(result).nl()
|
||||
debug_msg.msg("Response Code:").color(Color.ORANGE).bold().space().msg(response_code).nl()
|
||||
debug_msg.msg("Headers:").color(Color.ORANGE).bold().space().msg(headers).nl()
|
||||
debug_msg.msg("Body:").color(Color.ORANGE).bold().space().msg(body)
|
||||
debug_msg.debug()
|
||||
|
||||
## Inform the user about a received non-success response code.
|
||||
if response_code < 200 or response_code > 299:
|
||||
logger.msg("Discord responded with a non-success code: ").bold().msg(response_code, " - This is an indicator that something about the message you tried to send to Discord does not comply with their request body standards (e.g. content is too long, invalid format, etc.)").channel("terminal").warn()
|
||||
|
||||
http.queue_free()
|
||||
)
|
||||
|
||||
# Convert the [LoggieMsg]'s contents into markdown and post that to the target webhook url.
|
||||
var json = JSON.stringify({"content": output_text})
|
||||
var header = ["Content-Type: application/json"]
|
||||
|
||||
# Construct debug message.
|
||||
if debug_enabled:
|
||||
var debug_msg_post = logger.msg("Sending POST Request:").color(Color.CORNFLOWER_BLUE).header().channel("terminal").domain(debug_domain).nl()
|
||||
debug_msg_post.msg("JSON stringified (length {size}):".format({"size": output_text.length()})).color(Color.LIGHT_SLATE_GRAY).bold().space().msg(json).color(Color.SLATE_GRAY)
|
||||
debug_msg_post.debug()
|
||||
|
||||
# Send the request.
|
||||
http.request(webhook_url, header, HTTPClient.METHOD_POST, json)
|
||||
1
addons/loggie/channels/discord.gd.uid
Normal file
1
addons/loggie/channels/discord.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bqmohonxdfp2s
|
||||
65
addons/loggie/channels/slack.gd
Normal file
65
addons/loggie/channels/slack.gd
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
class_name SlackLoggieMsgChannel extends LoggieMsgChannel
|
||||
|
||||
var debug_domain = "_d_loggie_slack"
|
||||
var debug_enabled = false
|
||||
|
||||
func _init() -> void:
|
||||
self.ID = "slack"
|
||||
self.preprocess_flags = 0 # For this type of channel, this will be applied dynamically by Loggie after it loads LoggieSettings.
|
||||
|
||||
func send(msg : LoggieMsg, msg_type : LoggieEnums.MsgType):
|
||||
# Validate variables.
|
||||
var loggie = msg.get_logger()
|
||||
if loggie == null:
|
||||
push_error("Attempt to send a message that's coming from an invalid logger.")
|
||||
return
|
||||
|
||||
# Wait until loggie is inside tree so that we can use add_child(http) on it without errors.
|
||||
if !loggie.is_inside_tree():
|
||||
loggie.tree_entered.connect(func():
|
||||
send(msg, msg_type)
|
||||
, CONNECT_ONE_SHOT)
|
||||
return
|
||||
|
||||
var webhook = loggie.settings.slack_webhook_url_live if loggie.is_in_production() else loggie.settings.slack_webhook_url_dev
|
||||
if webhook == null or (webhook is String and webhook.is_empty()):
|
||||
push_error("Attempt to send a message to the Slack channel with an invalid webhook.")
|
||||
return
|
||||
|
||||
# Enable debug messages if configured.
|
||||
loggie.set_domain_enabled(debug_domain, debug_enabled)
|
||||
|
||||
# Create a new HTTPRequest POST request that will be sent to Slack and add it into the scenetree.
|
||||
var http = HTTPRequest.new()
|
||||
loggie.add_child(http)
|
||||
|
||||
# When the request is completed, destroy it.
|
||||
http.request_completed.connect(func(result, response_code, headers, body):
|
||||
var debug_msg = loggie.msg("HTTP Request Completed:").color(Color.ORANGE).header().domain(debug_domain)
|
||||
debug_msg.nl().msg("Result:").color(Color.ORANGE).bold().space().msg(result).nl()
|
||||
debug_msg.msg("Response Code:").color(Color.ORANGE).bold().space().msg(response_code).nl()
|
||||
debug_msg.msg("Headers:").color(Color.ORANGE).bold().space().msg(headers).nl()
|
||||
debug_msg.msg("Body:").color(Color.ORANGE).bold().space().msg(body)
|
||||
debug_msg.debug()
|
||||
|
||||
## Inform the user about a received non-success response code.
|
||||
if response_code < 200 or response_code > 299:
|
||||
loggie.msg("Slack responded with a non-success code: ").bold().msg(response_code, " - This is an indicator that something about the message you tried to send to Slack does not comply with their request body standards (e.g. content is too long, invalid format, etc.)").channel("terminal").warn()
|
||||
|
||||
http.queue_free()
|
||||
)
|
||||
|
||||
# Convert the [LoggieMsg]'s contents into markdown and post that to the target webhook url.
|
||||
var md_text = LoggieTools.convert_string_to_format_mode(msg.last_preprocess_result, LoggieEnums.MsgFormatMode.PLAIN)
|
||||
var json = JSON.stringify({"text": md_text})
|
||||
var header = ["Content-Type: application/json"]
|
||||
|
||||
# Construct debug message.
|
||||
if debug_enabled:
|
||||
var debug_msg_post = loggie.msg("Sending POST Request:").color(Color.ORANGE).header().domain(debug_domain).nl()
|
||||
debug_msg_post.msg("Preprocessed message:").color(Color.ORANGE).bold().space().msg(msg.last_preprocess_result).nl()
|
||||
debug_msg_post.msg("JSON stringified:").color(Color.ORANGE).bold().space().msg(json)
|
||||
debug_msg_post.debug()
|
||||
|
||||
# Send the request.
|
||||
http.request(webhook, header, HTTPClient.METHOD_POST, json)
|
||||
1
addons/loggie/channels/slack.gd.uid
Normal file
1
addons/loggie/channels/slack.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cw3nwdhr5xmgi
|
||||
21
addons/loggie/channels/terminal.gd
Normal file
21
addons/loggie/channels/terminal.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class_name TerminalLoggieMsgChannel extends LoggieMsgChannel
|
||||
|
||||
func _init() -> void:
|
||||
self.ID = "terminal"
|
||||
self.preprocess_flags = 0 # For this type of channel, this will be applied dynamically by Loggie after it loads LoggieSettings.
|
||||
|
||||
func send(msg : LoggieMsg, msg_type : LoggieEnums.MsgType):
|
||||
var loggie = msg.get_logger()
|
||||
var text = LoggieTools.convert_string_to_format_mode(msg.last_preprocess_result, loggie.settings.msg_format_mode)
|
||||
|
||||
match loggie.settings.msg_format_mode:
|
||||
LoggieEnums.MsgFormatMode.ANSI, LoggieEnums.MsgFormatMode.BBCODE:
|
||||
print_rich(text)
|
||||
LoggieEnums.MsgFormatMode.PLAIN, _:
|
||||
print(text)
|
||||
|
||||
# Dump a non-preprocessed terminal-ready version of the message in additional ways if that has been configured.
|
||||
if msg_type == LoggieEnums.MsgType.ERROR and loggie.settings.print_errors_to_console:
|
||||
push_error(LoggieTools.convert_string_to_format_mode(msg.string(), LoggieEnums.MsgFormatMode.PLAIN))
|
||||
if msg_type == LoggieEnums.MsgType.WARNING and loggie.settings.print_warnings_to_console:
|
||||
push_warning(LoggieTools.convert_string_to_format_mode(msg.string(), LoggieEnums.MsgFormatMode.PLAIN))
|
||||
1
addons/loggie/channels/terminal.gd.uid
Normal file
1
addons/loggie/channels/terminal.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bi8qfxuunsh1b
|
||||
Loading…
Add table
Add a link
Reference in a new issue