Skip to content

Commit

Permalink
Merge pull request #9 from Shiva-Shadowsong/v1.4-dev
Browse files Browse the repository at this point in the history
v1.4
  • Loading branch information
Shiva-Shadowsong authored Nov 2, 2024
2 parents be551ec + 69591cc commit 820b74b
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 90 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

# Only include the addons folder when downloading from the Asset Library.
/** export-ignore
/addons !export-ignore
/addons/** !export-ignore
28 changes: 15 additions & 13 deletions addons/loggie/custom_settings.gd.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ func load():
# You could also have them loaded here in some custom way, for example, from a .json or .ini file.
# See the documentation of the [LoggieSettings] class to see all available options and their descriptions.

self.terminal_mode = LoggieTools.TerminalMode.BBCODE
self.log_level = LoggieTools.LogLevel.INFO
self.show_loggie_specs = true
self.terminal_mode = LoggieEnums.TerminalMode.BBCODE
self.log_level = LoggieEnums.LogLevel.INFO
self.show_loggie_specs = LoggieEnums.ShowLoggieSpecsMode.ESSENTIAL
self.show_system_specs = true
self.output_message_domain = true
self.print_errors_to_console = true
self.print_warnings_to_console = true
self.use_print_debug_for_debug_msg = true
self.derive_and_show_class_names = true
self.nameless_class_name_proxy = LoggieTools.NamelessClassExtensionNameProxy.BASE_TYPE
self.show_timestamps = true
self.nameless_class_name_proxy = LoggieEnums.NamelessClassExtensionNameProxy.BASE_TYPE
self.output_timestamps = true
self.timestamps_use_utc = true

self.format_header = "[b][i]%s[/i][/b]"
self.format_domain_prefix = "[b](%s)[/b] %s"
self.format_error_msg = "[b][color=red][ERROR]:[/color][/b] %s"
self.format_warning_msg = "[b][color=orange][WARN]:[/color][/b] %s"
self.format_notice_msg = "[b][color=cyan][NOTICE]:[/color][/b] %s"
self.format_info_msg = "%s"
self.format_debug_msg = "[b][color=pink][DEBUG]:[/color][/b] %s"
self.format_timestamp = "[{day}.{month}.{year} {hour}:{minute}:{second}]"
self.format_info_msg = "{msg}"
self.format_notice_msg = "[b][color=cyan][NOTICE]:[/color][/b] {msg}"
self.format_warning_msg = "[b][color=orange][WARN]:[/color][/b] {msg}"
self.format_error_msg = "[b][color=red][ERROR]:[/color][/b] {msg}"
self.format_debug_msg = "[b][color=pink][DEBUG]:[/color][/b] {msg}"
self.format_header = "[b][i]{msg}[/i][/b]"
self.format_domain_prefix = "[b]({domain})[/b] {msg}"

self.h_separator_symbol = "-"
self.box_characters_mode = LoggieTools.BoxCharactersMode.COMPATIBLE
self.box_characters_mode = LoggieEnums.BoxCharactersMode.COMPATIBLE

self.box_symbols_compatible = {
"top_left" : "-",
Expand Down
5 changes: 3 additions & 2 deletions addons/loggie/loggie.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extends Node

## Stores a string describing the current version of Loggie.
const VERSION : String = "v1.3"
const VERSION : String = "v1.4"

## Emitted any time Loggie attempts to log a message.
## Useful for capturing the messages that pass through Loggie.
Expand All @@ -28,7 +28,7 @@ var domains : Dictionary = {}
## Holds a mapping between script paths and the names of the classes defined in those scripts.
var class_names : Dictionary = {}

func _ready() -> void:
func _init() -> void:
var uses_original_settings_file = true
var default_settings_path = get_script().get_path().get_base_dir().path_join("loggie_settings.gd")
var custom_settings_path = get_script().get_path().get_base_dir().path_join("custom_settings.gd")
Expand All @@ -46,6 +46,7 @@ func _ready() -> void:
self.settings.load()
if is_in_production():
self.settings.terminal_mode = LoggieEnums.TerminalMode.PLAIN
self.settings.box_characters_mode = LoggieEnums.BoxCharactersMode.COMPATIBLE
else:
push_error("Loggie loaded neither a custom nor a default settings file. This will break the plugin. Make sure that a valid loggie_settings.gd is in the same directory where loggie.gd is.")
return
Expand Down
56 changes: 31 additions & 25 deletions addons/loggie/loggie_message.gd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func output(level : LoggieEnums.LogLevel, msg : String, domain : String = "") ->
if self.preprocess:
# We append the name of the domain if that setting is enabled.
if !domain.is_empty() and loggie.settings.output_message_domain == true:
msg = loggie.settings.format_domain_prefix % [domain, msg]
msg = loggie.settings.format_domain_prefix.format({"domain" : domain, "msg" : msg})

# We prepend the name of the class that called the function which resulted in this output being generated
# (if Loggie settings are configured to do so).
Expand All @@ -94,9 +94,10 @@ func output(level : LoggieEnums.LogLevel, msg : String, domain : String = "") ->
})

# We prepend a timestamp to the message (if Loggie settings are configured to do so).
if loggie.settings.show_timestamps == true:
msg = "{timestamp} {msg}".format({
"timestamp" : Time.get_datetime_string_from_system(loggie.settings.timestamps_use_utc, true),
if loggie.settings.output_timestamps == true:
var format_dict : Dictionary = Time.get_datetime_dict_from_system(loggie.settings.timestamps_use_utc)
msg = "{formatted_time} {msg}".format({
"formatted_time" : loggie.settings.format_timestamp.format(format_dict),
"msg" : msg
})

Expand All @@ -122,46 +123,51 @@ func output(level : LoggieEnums.LogLevel, msg : String, domain : String = "") ->
## The [Loggie.settings.log_level] must be equal to or higher to the ERROR level for this to work.
func error() -> LoggieMsg:
var loggie = get_logger()
var msg = loggie.settings.format_error_msg % [self.content]
output(LoggieEnums.LogLevel.ERROR, msg, self.domain_name)
if loggie.settings.print_errors_to_console and loggie.settings.log_level >= LoggieEnums.LogLevel.ERROR:
push_error(self.string())
if loggie != null and loggie.settings != null:
var msg = loggie.settings.format_error_msg.format({"msg": self.content})
output(LoggieEnums.LogLevel.ERROR, msg, self.domain_name)
if loggie.settings.print_errors_to_console and loggie.settings.log_level >= LoggieEnums.LogLevel.ERROR:
push_error(self.string())
return self

## Outputs this message from Loggie as an Warning type message.
## The [Loggie.settings.log_level] must be equal to or higher to the WARN level for this to work.
func warn() -> LoggieMsg:
var loggie = get_logger()
var msg = loggie.settings.format_warning_msg % [self.content]
output(LoggieEnums.LogLevel.WARN, msg, self.domain_name)
if loggie.settings.print_warnings_to_console and loggie.settings.log_level >= LoggieEnums.LogLevel.WARN:
push_warning(self.string())
if loggie != null and loggie.settings != null:
var msg = loggie.settings.format_warning_msg.format({"msg": self.content})
output(LoggieEnums.LogLevel.WARN, msg, self.domain_name)
if loggie.settings.print_warnings_to_console and loggie.settings.log_level >= LoggieEnums.LogLevel.WARN:
push_warning(self.string())
return self

## Outputs this message from Loggie as an Notice type message.
## The [Loggie.settings.log_level] must be equal to or higher to the NOTICE level for this to work.
func notice() -> LoggieMsg:
var loggie = get_logger()
var msg = loggie.settings.format_notice_msg % [self.content]
output(LoggieEnums.LogLevel.NOTICE, msg, self.domain_name)
if loggie != null and loggie.settings != null:
var msg = loggie.settings.format_notice_msg.format({"msg": self.content})
output(LoggieEnums.LogLevel.NOTICE, msg, self.domain_name)
return self

## Outputs this message from Loggie as an Info type message.
## The [Loggie.settings.log_level] must be equal to or higher to the INFO level for this to work.
func info() -> LoggieMsg:
var loggie = get_logger()
var msg = loggie.settings.format_info_msg % [self.content]
output(LoggieEnums.LogLevel.INFO, msg, self.domain_name)
if loggie != null and loggie.settings != null:
var msg = loggie.settings.format_info_msg.format({"msg": self.content})
output(LoggieEnums.LogLevel.INFO, msg, self.domain_name)
return self

## Outputs this message from Loggie as a Debug type message.
## The [Loggie.settings.log_level] must be equal to or higher to the DEBUG level for this to work.
func debug() -> LoggieMsg:
var loggie = get_logger()
var msg = loggie.settings.format_debug_msg % [self.content]
output(LoggieEnums.LogLevel.DEBUG, msg, self.domain_name)
if loggie.settings.use_print_debug_for_debug_msg and loggie.settings.log_level >= LoggieEnums.LogLevel.DEBUG:
print_debug(self.string())
if loggie != null and loggie.settings != null:
var msg = loggie.settings.format_debug_msg.format({"msg": self.content})
output(LoggieEnums.LogLevel.DEBUG, msg, self.domain_name)
if loggie.settings.use_print_debug_for_debug_msg and loggie.settings.log_level >= LoggieEnums.LogLevel.DEBUG:
print_debug(self.string())
return self

## Returns the string content of this message.
Expand Down Expand Up @@ -193,23 +199,23 @@ func color(_color : Variant) -> LoggieMsg:
if _color is Color:
_color = _color.to_html()

self.content = "[color=%s]%s[/color]" % [_color, self.content]
self.content = "[color={colorstr}]{msg}[/color]".format({"colorstr": _color, "msg": self.content})
return self

## Stylizes the current content of this message to be bold.
func bold() -> LoggieMsg:
self.content = "[b]%s[/b]" % [self.content]
self.content = "[b]{msg}[/b]".format({"msg": self.content})
return self

## Stylizes the current content of this message to be italic.
func italic() -> LoggieMsg:
self.content = "[i]%s[/i]" % [self.content]
self.content = "[i]{msg}[/i]".format({"msg": self.content})
return self

## Stylizes the current content of this message as a header.
func header() -> LoggieMsg:
var loggie = get_logger()
self.content = loggie.settings.format_header % self.content
self.content = loggie.settings.format_header.format({"msg": self.content})
return self

## Constructs a decorative box with the given horizontal padding around the current content
Expand Down Expand Up @@ -301,7 +307,7 @@ func hseparator(size : int = 16, alternative_symbol : Variant = null) -> LoggieM
## Sets whether this message should be preprocessed and potentially modified with prefixes and suffixes during [method output].
## If turned off, while outputting this message, Loggie will skip the steps where it appends the messaage domain, class name, timestamp, etc.
## Whether preprocess is set to true doesn't affect the final conversion from RICH to ANSI or PLAIN, which always happens
## under some circumstances that based on other settings.
## under some circumstances that are based on other settings.
func preprocessed(shouldPreprocess : bool) -> LoggieMsg:
self.preprocess = shouldPreprocess
return self
Loading

0 comments on commit 820b74b

Please sign in to comment.