Skip to content

ModLoaderLog

KANAjetzt edited this page Jun 16, 2023 · 6 revisions

ModLoaderLog

Extends: Node

Description

This Class provides methods for logging, retrieving logged data, and internal methods for working with log files.

Enumerations

VERBOSITY_LEVEL

const VERBOSITY_LEVEL: Dictionary = {"DEBUG":3,"ERROR":0,"INFO":2,"WARNING":1}

Constants Descriptions

LOG_NAME

const LOG_NAME: String = "ModLoader:Log"

MOD_LOG_PATH

const MOD_LOG_PATH: String = "user://logs/modloader.log"

Path to the latest log file.

Method Descriptions

fatal (static)

func fatal(message: String, mod_name: String, only_once: bool = false) -> void

Logs the error in red and a stack trace. Prefixed FATAL-ERROR.

Note: Stops the execution in editor

Parameters:

  • message (String): The message to be logged as an error.
  • mod_name (String): The name of the mod or ModLoader class associated with this log entry.
  • only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.

Returns: void

error (static)

func error(message: String, mod_name: String, only_once: bool = false) -> void

Logs the message and pushes an error. Prefixed ERROR.

Note: Always logged

Parameters:

  • message (String): The message to be logged as an error.
  • mod_name (String): The name of the mod or ModLoader class associated with this log entry.
  • only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.

Returns: void

warning (static)

func warning(message: String, mod_name: String, only_once: bool = false) -> void

Logs the message and pushes a warning. Prefixed WARNING.

Note: Logged with verbosity level at or above warning (-v).

Parameters:

  • message (String): The message to be logged as a warning.
  • mod_name (String): The name of the mod or ModLoader class associated with this log entry.
  • only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.

Returns: void

info (static)

func info(message: String, mod_name: String, only_once: bool = false) -> void

Logs the message. Prefixed INFO.

Note: Logged with verbosity level at or above info (-vv).

Parameters:

  • message (String): The message to be logged as an information.
  • mod_name (String): The name of the mod or ModLoader class associated with this log entry.
  • only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.

Returns: void

success (static)

func success(message: String, mod_name: String, only_once: bool = false) -> void

Logs the message. Prefixed SUCCESS.

Note: Logged with verbosity level at or above info (-vv).

Parameters:

  • message (String): The message to be logged as a success.
  • mod_name (String): The name of the mod or ModLoader class associated with this log entry.
  • only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.

Returns: void

debug (static)

func debug(message: String, mod_name: String, only_once: bool = false) -> void

Logs the message. Prefixed DEBUG.

Note: Logged with verbosity level at or above debug (-vvv).

Parameters:

  • message (String): The message to be logged as a debug.
  • mod_name (String): The name of the mod or ModLoader class associated with this log entry.
  • only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.

Returns: void

debug_json_print (static)

func debug_json_print(message: String, json_printable, mod_name: String, only_once: bool = false) -> void

Logs the message formatted with [method JSON.print]. Prefixed DEBUG.

Note: Logged with verbosity level at or above debug (-vvv).

Parameters:

  • message (String): The message to be logged as a debug.
  • json_printable (Variant): The variable to be formatted and printed using [method JSON.print].
  • mod_name (String): The name of the mod or ModLoader class associated with this log entry.
  • only_once (bool): (Optional) If true, the log entry will only be logged once, even if called multiple times. Default is false.

Returns: void

get_all_as_resource (static)

func get_all_as_resource() -> Array

Returns an array of log entries as a resource.

Returns:

  • Array: An array of log entries represented as resource.

get_all_as_string (static)

func get_all_as_string() -> Array

Returns an array of log entries as a string.

Returns:

  • Array: An array of log entries represented as strings.

get_by_mod_as_resource (static)

func get_by_mod_as_resource(mod_name: String) -> Array

Returns an array of log entries as a resource for a specific mod_name.

Parameters:

  • mod_name (String): The name of the mod or ModLoader class associated with the log entries.

Returns:

  • Array: An array of log entries represented as resource for the specified mod_name.

get_by_mod_as_string (static)

func get_by_mod_as_string(mod_name: String) -> Array

Returns an array of log entries as a string for a specific mod_name.

Parameters:

  • mod_name (String): The name of the mod or ModLoader class associated with the log entries.

Returns:

  • Array: An array of log entries represented as strings for the specified mod_name.

get_by_type_as_resource (static)

func get_by_type_as_resource(type: String) -> Array

Returns an array of log entries as a resource for a specific type.

Parameters:

  • type (String): The log type associated with the log entries.

Returns:

  • Array: An array of log entries represented as resource for the specified type.

get_by_type_as_string (static)

func get_by_type_as_string(type: String) -> Array

Returns an array of log entries as a string for a specific type.

Parameters:

  • type (String): The log type associated with the log entries.

Returns:

  • Array: An array of log entries represented as strings for the specified type.

get_all (static)

func get_all() -> Array

Returns an array of all log entries.

Returns:

  • Array: An array of all log entries.

get_by_mod (static)

func get_by_mod(mod_name: String) -> Array

Returns an array of log entries for a specific mod_name.

Parameters:

  • mod_name (String): The name of the mod or ModLoader class associated with the log entries.

Returns:

  • Array: An array of log entries for the specified mod_name.

get_by_type (static)

func get_by_type(type: String) -> Array

Returns an array of log entries for a specific type.

Parameters:

  • type (String): The log type associated with the log entries.

Returns:

  • Array: An array of log entries for the specified type.

get_all_entries_as_string (static)

func get_all_entries_as_string(log_entries: Array) -> Array

Returns an array of log entries represented as strings.

Parameters:

  • log_entries (Array): An array of ModLoaderLogEntry Objects.

Returns:

  • Array: An array of log entries represented as strings.

Sub-classes

ModLoaderLogEntry

Property Descriptions

mod_name

var mod_name: String

Name of the mod or ModLoader class this entry refers to.

message

var message: String

The message of the log entry.

type

var type: String

The log type, which indicates the verbosity level of this entry.

time

var time: String

The readable format of the time when this log entry was created. Used for printing in the log file and output.

time_stamp

var time_stamp: int

The timestamp when this log entry was created. Used for comparing and sorting log entries by time.

stack

var stack: Array

An array of ModLoaderLogEntry objects. If the message has been logged before, it is added to the stack.

Method Descriptions

_init

func _init(_mod_name: String, _message: String, _type: String, _time: String) -> void

Initialize a ModLoaderLogEntry object with provided values.

Parameters:

  • _mod_name (String): Name of the mod or ModLoader class this entry refers to.
  • _message (String): The message of the log entry.
  • _type (String): The log type, which indicates the verbosity level of this entry.
  • _time (String): The readable format of the time when this log entry was created.

Returns: void

get_entry

func get_entry() -> String

Get the log entry as a formatted string.

Returns: String

get_prefix

func get_prefix() -> String

Get the prefix string for the log entry, including the log type and mod name.

Returns: String

get_md5

func get_md5() -> String

Generate an MD5 hash of the log entry (prefix + message).

Returns: String

get_all_entries

func get_all_entries() -> Array

Get all log entries, including the current entry and entries in the stack.

Returns: Array

ModLoaderLogCompare

Method Descriptions

time (static)

func time(a: ModLoaderLogEntry, b: ModLoaderLogEntry) -> bool

Custom sorter that orders logs by time

Clone this wiki locally