Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions addons/mod_loader/api/config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ static func get_mod_config(mod_dir_name: String = "", key: String = "") -> Dicti
# No user config file exists. Low importance as very likely to trigger
var full_msg = "Config JSON Notice: %s" % status_msg
# Only log this once, to avoid flooding the log
if not ModLoaderStore.logged_messages.all.has(full_msg.md5_text()):
ModLoaderLog.debug(full_msg, mod_dir_name)
ModLoaderLog.debug(full_msg, mod_dir_name, true)
else:
# Code error (eg. invalid mod ID)
ModLoaderLog.fatal("Config JSON Error (%s): %s" % [status_code, status_msg], mod_dir_name)
Expand Down
41 changes: 26 additions & 15 deletions addons/mod_loader/api/log.gd
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,45 @@ class ModLoaderLogEntry:
# Logs the error in red and a stack trace. Prefixed FATAL-ERROR
# Stops the execution in editor
# Always logged
static func fatal(message: String, mod_name: String) -> void:
_log(message, mod_name, "fatal-error")
static func fatal(message: String, mod_name: String, only_once := false) -> void:
_log(message, mod_name, "fatal-error", only_once)


# Logs the message and pushed an error. Prefixed ERROR
# Always logged
static func error(message: String, mod_name: String) -> void:
_log(message, mod_name, "error")
static func error(message: String, mod_name: String, only_once := false) -> void:
_log(message, mod_name, "error", only_once)


# Logs the message and pushes a warning. Prefixed WARNING
# Logged with verbosity level at or above warning (-v)
static func warning(message: String, mod_name: String) -> void:
_log(message, mod_name, "warning")
static func warning(message: String, mod_name: String, only_once := false) -> void:
_log(message, mod_name, "warning", only_once)


# Logs the message. Prefixed INFO
# Logged with verbosity level at or above info (-vv)
static func info(message: String, mod_name: String) -> void:
_log(message, mod_name, "info")
static func info(message: String, mod_name: String, only_once := false) -> void:
_log(message, mod_name, "info", only_once)


# Logs the message. Prefixed SUCCESS
# Logged with verbosity level at or above info (-vv)
static func success(message: String, mod_name: String) -> void:
_log(message, mod_name, "success")
static func success(message: String, mod_name: String, only_once := false) -> void:
_log(message, mod_name, "success", only_once)


# Logs the message. Prefixed DEBUG
# Logged with verbosity level at or above debug (-vvv)
static func debug(message: String, mod_name: String) -> void:
_log(message, mod_name, "debug")
static func debug(message: String, mod_name: String, only_once := false) -> void:
_log(message, mod_name, "debug", only_once)


# Logs the message formatted with [method JSON.print]. Prefixed DEBUG
# Logged with verbosity level at or above debug (-vvv)
static func debug_json_print(message: String, json_printable, mod_name: String) -> void:
static func debug_json_print(message: String, json_printable, mod_name: String, only_once := false) -> void:
message = "%s\n%s" % [message, JSON.print(json_printable, " ")]
_log(message, mod_name, "debug")
_log(message, mod_name, "debug", only_once)


# API log functions - stored logs
Expand Down Expand Up @@ -186,12 +186,16 @@ static func get_all_entries_as_string(log_entries: Array) -> Array:
# Internal log functions
# =============================================================================

static func _log(message: String, mod_name: String, log_type: String = "info") -> void:
static func _log(message: String, mod_name: String, log_type: String = "info", only_once := false) -> void:
if _is_mod_name_ignored(mod_name):
return

var time := "%s " % _get_time_string()
var log_entry := ModLoaderLogEntry.new(mod_name, message, log_type, time)

if only_once and _is_logged_before(log_entry):
return

_store_log(log_entry)

# Check if the scene_tree is available
Expand Down Expand Up @@ -266,6 +270,13 @@ static func _store_log(log_entry: ModLoaderLogEntry) -> void:
ModLoaderStore.logged_messages.by_type[log_entry.type.to_lower()][log_entry.get_md5()] = log_entry


static func _is_logged_before(entry: ModLoaderLogEntry) -> bool:
if not ModLoaderStore.logged_messages.all.has(entry.get_md5()):
return false

return true


class ModLoaderLogCompare:
# Custom sorter that orders logs by time
static func time(a: ModLoaderLogEntry, b: ModLoaderLogEntry) -> bool:
Expand Down