Refactor logging#50
Conversation
7e9df63 to
567c538
Compare
|
Fixes #30 |
Zoriot
left a comment
There was a problem hiding this comment.
Thanks for the PR! Generally looks good to, comment's regarding parameterized logging & component logger apply to all changes/loggings.
|
|
||
| private void updateConfig() { | ||
| FileBuilder fileBuilder = new FileBuilder(this); | ||
| PluginConfigManipulator manipulator = new PluginConfigManipulator(this); |
There was a problem hiding this comment.
Please move this in another Class
There was a problem hiding this comment.
Not sure I understand what you want to see moved. The hole updateConfig() method?
There was a problem hiding this comment.
Yea, that could be Split up a bit too, but not necessarily. Like having a Method per Version. But we shouldn't put too much time into that.
There was a problem hiding this comment.
Imo that needs to be entirely reworked, so I did not address it in that PR. All I did was rewriting FileBuilder into PluginConfigManipulator where I was able to cleanup logging without the duplicated code and weird static side effects. I don't really want to touch updateConfig() in this PR beyond logging and trivial warnings like multi-line strings.
There was a problem hiding this comment.
Imo that already broke the scope of the pr & should be mentioned in the title. Or moved to another pr.
Changing that to a whole new System (even when it's kinda working the Same under the hood) is a quite big change regarding the config system.
Still think this method is completely wrong in the main class and it's also stupid that you have to touch main class when just adding an option for xy.
There was a problem hiding this comment.
Changing that to a whole new System (even when it's kinda working the Same under the hood) is a quite big change regarding the config system.
The system is exactly the same and all changes are syntactic:
- Removed unused methods
- Made a static field an instance field (because it had no business being static and that was very confusing)
- Removed duplicated code by leveraging lambdas (this was necessary to avoid copy-pasting logging statements in 3 different places...)
- Renamed the class because its name was very confusing.
Copilot is even complaining about problems that were carried over from the original code down below 😅 because I did not address anything else.
There was a problem hiding this comment.
Yes, it should be moved elsewhere. I did some changes that I felt were necessary to improve logging, but I don't think going further would be in scope at all for this PR. As you said it yourself some of the changes are already reaching the limit.
There was a problem hiding this comment.
Can you please make an issue for that?
There was a problem hiding this comment.
Pull Request Overview
This PR refactors logging and error handling across the plugin to modernize the codebase. The changes migrate from legacy logging APIs to Paper's ComponentLogger, improve error handling with more descriptive messages, and extract config manipulation functionality into a dedicated utility class.
- Migrated all logging from
Bukkit.getLogger()andjava.util.logging.Levelto Paper'sComponentLoggerAPI - Refactored the
FileBuilderclass into a focusedPluginConfigManipulatorutility for config file manipulation - Improved exception handling with better error messages and appropriate logging levels
- Fixed logic issues in
WhereCommandwhere coordinates array could be uninitialized
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| PluginConfigManipulator.java | New utility class that extracts config file manipulation methods from FileBuilder with improved error handling |
| FileBuilder.java | Deleted legacy class that mixed YAML configuration access with file manipulation |
| TreePopulator.java | Migrated logging to ComponentLogger and improved exception messages |
| CustomBiomeProvider.java | Improved exception handling by silencing expected OutOfProjectionBoundsException and logging unexpected ones |
| PluginMessageEvent.java | Migrated logging to ComponentLogger |
| PlayerMoveEvent.java | Migrated logging to ComponentLogger and removed unused imports |
| WhereCommand.java | Fixed potential NPE by restructuring coordinate calculation and improved error handling |
| Terraplusminus.java | Comprehensive logging migration, refactored datapack installation logic, and updated config migration to use new PluginConfigManipulator |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| e.printStackTrace(); | ||
| Bukkit.getLogger().log(Level.SEVERE, "[T+-] Old config detected. Please delete and restart/reload."); | ||
| if (configVersion == 0.0) { // That's the default value if the field was not set at all in the YAML | ||
| this.getComponentLogger().error("Old config detected. Please delete and restart/reload."); |
There was a problem hiding this comment.
When an old config is detected (version 0.0), the method logs an error but continues execution. This will cause all subsequent if (configVersion == X.X) checks to fail, and the config will remain outdated. The method should return early after logging the error to prevent further processing.
| this.getComponentLogger().error("Old config detected. Please delete and restart/reload."); | |
| this.getComponentLogger().error("Old config detected. Please delete and restart/reload."); | |
| return; |
There was a problem hiding this comment.
This problem was already there. I don't want to half address it as the whole logic flow for configuration upgrades is flawed (e.g. upgrading from 1.1 to 1.5 will only upgrade the configuration to 1.2...), and that's out of scope for this PR.
There was a problem hiding this comment.
Document it by an issue so it can/will be fixed
e315b7d to
aec51e9
Compare
|
|
||
| private void updateConfig() { | ||
| FileBuilder fileBuilder = new FileBuilder(this); | ||
| PluginConfigManipulator manipulator = new PluginConfigManipulator(this); |
There was a problem hiding this comment.
Can you please make an issue for that?
| e.printStackTrace(); | ||
| Bukkit.getLogger().log(Level.SEVERE, "[T+-] Old config detected. Please delete and restart/reload."); | ||
| if (configVersion == 0.0) { // That's the default value if the field was not set at all in the YAML | ||
| this.getComponentLogger().error("Old config detected. Please delete and restart/reload."); |
There was a problem hiding this comment.
Document it by an issue so it can/will be fixed
- Do not use this.config to access the configuration static field (ideally the configuration should not be in a static field, a complete rewrite of the config system is needed on that side). - Rename FileBuilder to PluginConfigManipulator and make it use instance fields and methods; remove all unused methods and rewrite the remaining ones to eliminate duplicated code and warnings, and use Java best practices like try-with blocks. - Use multiple strings I do believe this will have to be replaced at some point in the future and is still suboptimal, but at least it should be a lot less confusing and more manageable now.
…stead of silently failing and printing a useless stack trace
aec51e9 to
ada5332
Compare
These kind of multiline logs add nothing of value besides "looking cool" and make logs harder to read, search and process for server admins.
ada5332 to
9bb4b88
Compare
|
@Zoriot if this is approved, can we go ahead and merge it? Or is there anything else that needs improvement or clarification? |
This PR aims to improve the overall logging situation within the plugin.
Most importantly, it makes sure all outputs coming from Terra+- go through its plugin logger. This makes sure it can be properly instrumented using Log4J and JUL configuration capabilities. For example, a server administrator might want to set the Terra+- logger's level to
traceand mute all other plugins, all the while saving latest.log as JSON so it can be latter be grammatically analyzed. This means all calls toSystem#outorException#printStackTrace()have been removed or replaced with logger calls.This implies changes in what exactly gets logged. Some messages have changed, some errors are redirected to end users (see changes for the
/wherecommand), and some things are simply no longer logged.Two specific parts of the plugins were also rewritten more substantially with the goal to improve them, as substantial rewrites were necessary anyway to better handle and logging errors. This concerns automatic datapack installation and automatic configuration upgrade. Behavior should not change. Also, while I feel like the configuration part is somewhat better with those changes, I still think it has many issues.
Finally, I have removed the ascii-art that gets logged on startup, and replaced it with a simple line that prints the Terra+- and Terra-- versions, as it does clutter server logs with little benefits.
For reference, this is what Terra+- logs when starting and stopping a server (by default only INFO messages would be shown):