Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: ♻️ Logging + ✨ Store Logs #205

Merged
merged 31 commits into from
Apr 17, 2023

Conversation

KANAjetzt
Copy link
Member

@KANAjetzt KANAjetzt commented Mar 31, 2023

Logging refactor

  • Moved log utils into its one file (res://addons/mod_loader/api/log.gd) and Class (ModLoaderLog).
  • New Resource for log entries ModLoaderLogEntry
  • New util functions to work with stored logs
    • get_all_as_resource_array()
    • get_all_as_string_array()
    • get_by_mod_as_resource_array(mod_name: String)
    • get_by_mod_as_string_array(mod_name: String)
    • get_by_type_as_resource_array(type: String)
    • get_by_type_as_string_array(type: String)

Edit (Darkly77): This PR also introduces the feature of storing logged messages (via _store_log), which gives purpose to the methods listed above.

Todos

  • Move functions to ModLoaderLog
    • _write_to_log_file
    • _rotate_log_file
    • _clear_old_log_backups
    • _is_mod_name_ignored
    • _get_verbosity
    • _loader_log
    • _get_time_string
    • _get_date_string
    • _get_date_time_string
  • Move functions to ModLoaderLog and leave deprecation() func
    • log_fatal -> ModLoaderLog.fatal
    • log_error -> ModLoaderLog.error
    • log_warning -> ModLoaderLog.warning
    • log_info -> ModLoaderLog.info
    • log_success -> ModLoaderLog.success
    • log_debug -> ModLoaderLog.debug
    • log_debug_json_print -> ModLoaderLog.debug_json_print
  • Add ignored_mod_names_in_log to ml_options in ModLoaderStore and options_profile.gd
  • update get_mod_config() in config.gd line 73 and 75
  • Add get_all_as_resource()
  • Add get_all_as_string()
  • Add get_by_mod_as_resource(mod_name: String)
  • Add get_by_mod_as_string(mod_name: String)
  • Add get_by_type_as_resource(type: String)
  • Add get_by_type_as_string(type: String)
  • Error Handling
    • Check if key exists in get_by_mod(mod_name: String)

Test Mod

KANA-LogViewer.zip

Related Issues

@KANAjetzt KANAjetzt added enhancement New feature or request refactor / cleanup Improves readability or maintainability labels Mar 31, 2023
@KANAjetzt KANAjetzt added this to the v6.0.0 milestone Mar 31, 2023
@KANAjetzt KANAjetzt requested review from Qubus0 and a team March 31, 2023 22:33
@KANAjetzt KANAjetzt changed the title refactor: ♻️ created LogManager and LogEntry Class refactor: ♻️ created LogManager and LogEntry Class Mar 31, 2023
@KANAjetzt
Copy link
Member Author

Oh and I still need to fix this:

Working on this now. Just so I don't forget update get_mod_config() in config.gd line 73 and 75:

if not ModLoaderStore.logged_messages.has(full_msg):
   ModLoaderUtils.log_debug(full_msg, mod_dir_name)
   ModLoaderStore.logged_messages.push_back(full_msg)

@ithinkandicode
Copy link
Collaborator

ithinkandicode commented Apr 1, 2023

I was thinking the log funcs would be moved to ./add_ons/mod_loader/api/log.gd?

And that the class would follow the standard of other API classes, ie. ModLoaderLog. That follows the established standard and retains the namespaced class names.

Note: The current classes directory might be misnamed (my fault), as it's actually only used for resources. The functional classes are actually in api now.

@ithinkandicode
Copy link
Collaborator

ithinkandicode commented Apr 2, 2023

I've looked over this PR's code in more detail and I have some notes.

There are still logging methods in ModLoaderUtils. Can they all be moved to ModLoaderLog please? And leave deprecation funcs behind -- eg. see #208, which moves methods from ModLoader.* to ModLoaderMod.*

How come you've used a class instance for LogManager? Why not use it with static methods, like other API methods do? Then you can log things with ModLoaderLog.method, rather than ModLoaderStore.LogManager.method.

Generally I think we should keep the ModLoaderFoo standard of class names. This makes it easier to identify methods that originate with ModLoader, and avoids potential conflicts with games/mods that use more generic class names (eg. an existing game might already have a class called LogManager, but it definitely won't have a class called ModLoaderLog).

You've used ModLoaderStore to store a class instance, but it's not intended to be used that way. It's meant to be a simple data store, partly to fix using local vars in ModLoader (see #161 + #172), but also to fix the issue of static class methods being unable to save data to their own class's local variables (because that class hasn't been instanced). So now instead, they can store data to ModLoaderStore. In this case, ModLoaderStore lets you keep track of any logged messages, via ModLoaderStore.logged_messages. So all your static methods can still exist in ModLoaderLog, but you can also save data, like logged messaged, to ModLoaderStore.

@KANAjetzt
Copy link
Member Author

I will rework this to account for #153.
Ty @ithinkandicode for the review 👍

@KANAjetzt KANAjetzt changed the title refactor: ♻️ created LogManager and LogEntry Class refactor: ♻️ store logged messages Apr 3, 2023
@KANAjetzt KANAjetzt added the breaking Breaking change label Apr 4, 2023
Moved most of the logging logic from `ModLoaderUtils` into `LogManager`. New `LogEntry` Class to store log message info. Added log storing in `LogManager`.

works towards GodotModding#140
Based on the discussion in GodotModding#153 - Some compromises had to be done to prevent cyclic reference errors. No `ModLoaderUtils` functions could be used.
Had to copy the required utility functions into the setup script, because `ModLoaderUtils` depends now on other Classes that don't get loaded.
With that the ModLoaderLog Class is fully independed and can be loaded in the setup script.
accidentally removed the `log_` from the deprecation message and `log_debug_json_print`.
There tradeoffs for using the existing ModLoader Classes in the setup script are to big. So the required functions where moved into the *setup/* dir.
@ithinkandicode
Copy link
Collaborator

Should this PR be called "Logging Refactor", instead of "store logged messages"? Just thinking of the commit message which is set automatically from the PR title

@KANAjetzt KANAjetzt changed the title refactor: ♻️ store logged messages refactor: ♻️ Logging Refactor Apr 7, 2023
@KANAjetzt
Copy link
Member Author

good point

addons/mod_loader/setup/setup_log.gd Outdated Show resolved Hide resolved
addons/mod_loader/setup/setup_utils.gd Outdated Show resolved Hide resolved
Added `time_stamp` to `ModLoaderLogEntry` and instead of saving the `time` string in `time_stamps` the same log entries are now stored in `stack`. Added `ModLoaderLogCompare` inner class, allowing to call the custom sort function.
@KANAjetzt KANAjetzt changed the title refactor: ♻️ Logging Refactor refactor: ♻️ Logging Apr 11, 2023
@KANAjetzt KANAjetzt self-assigned this Apr 14, 2023
Copy link
Collaborator

@Qubus0 Qubus0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only minor things.
very nice work 🚀

addons/mod_loader/api/log.gd Show resolved Hide resolved
addons/mod_loader/api/log.gd Outdated Show resolved Hide resolved
addons/mod_loader/mod_loader_store.gd Outdated Show resolved Hide resolved
Added description for `ignored_mod_names_in_log` in `ModLoaderStore` and removed the `;` in the `_rotate_log_file()` comment.
@KANAjetzt KANAjetzt added this pull request to the merge queue Apr 17, 2023
Merged via the queue into GodotModding:development with commit a14a632 Apr 17, 2023
@KANAjetzt KANAjetzt deleted the refactor_logs branch April 17, 2023 19:07
@ithinkandicode ithinkandicode changed the title refactor: ♻️ Logging refactor: ♻️ Logging + ✨ Store Logs May 7, 2023
@ithinkandicode ithinkandicode linked an issue May 7, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking change enhancement New feature or request refactor / cleanup Improves readability or maintainability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging: Track logged messages
3 participants