-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Allow plugins to use SLF4J for logging #890
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
Conversation
| private FileConfiguration newConfig = null; | ||
| private File configFile = null; | ||
| - private PluginLogger logger = null; | ||
| + private Logger logger = null; // Paper: PluginLogger -> Logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Paper - PluginLogger -> Logger
| this.classLoader = classLoader; | ||
| this.configFile = new File(dataFolder, "config.yml"); | ||
| - this.logger = new PluginLogger(this); | ||
| + this.logger = Logger.getLogger(description.getName()); // Paper: Handle plugin prefix in implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Paper - Handle plugin prefix in implementation
| <scope>runtime</scope> | ||
| </dependency> | ||
|
|
||
| + <!-- Paper: Add additional Log4J dependencies --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- Paper - Add additional Log4J dependencies -->
| </relocation> | ||
| </relocations> | ||
| <transformers> | ||
| + <!-- Paper: Exclude log4j2-test.xml --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- Paper - Exclude log4j2-test.xml -->
| <scope>compile</scope> | ||
| </dependency> | ||
|
|
||
| + <!-- Paper: Add SLF4J --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- Paper - Add SLF4J -->
| { | ||
| playerSample = getInt( "settings.sample-count", 12 ); | ||
| - System.out.println( "Server Ping Player Sample Count: " + playerSample ); | ||
| + Bukkit.getLogger().log( Level.INFO, "Server Ping Player Sample Count: {0}", playerSample ); // Paper: Use logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Paper - Use logger
|
Have you tested this with some popular plugins, such as |
|
@kashike I tested this with the incredibly popular |
| this.classLoader = classLoader; | ||
| this.configFile = new File(dataFolder, "config.yml"); | ||
| - this.logger = new PluginLogger(this); | ||
| + this.logger = Logger.getLogger(description.getName()); // Paper: Handle plugin prefix in implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be getPrefix().
|
@kashike All fixed. I tested with Essentials and WorldEdit and after some work log messages are now visible. Essentials needs a workaround because it uses the WorldEdit works correctly but it doesn't use the plugin logger either so a different logger name is displayed in some cases. Example log: https://gist.github.com/Minecrell/53eb99d4e06eb006b30f7a67decd7be9#file-gistfile1-txt-L104-L119 |
|
Tested a "few" more plugins. All plugins are working but mostly older, large plugins bypass the plugin logger entirely and add the plugin prefix manually. Some of these plugins (marked with ❗️) will now show the full qualified logger name additionally. We could white-list the packages manually as a workaround...
|
|
I disabled the logger prefix manually for The implementation in this PR works correctly, it's only plugins that bypass the plugin loggers which may cause issues. |
|
Could you provide an updated log, please? |
|
@kashike I could. Maybe I will... Actually, why not? https://gist.github.com/Minecrell/35f5dbb69eefaa3137daece6224588a4 |
|
@kashike Log with latest Paper build without my changes: https://gist.github.com/Minecrell/daa3e038f47751ed380fba661d3def73 |
|
Opened similar PR for Waterfall: PaperMC/Waterfall#176 |
|
Moved plugin prefix back to behind the |
Log4j2 provides an optimized implementation of PrintStream that redirects its output to a logger. Use it instead of a custom implementation for minor performance improvements and some fixes. With the old implementation, each call to System.print() results in a separate line, even though it should not result in a line break. Log4j's implementation handles it correctly.
SLF4J is a commonly used abstraction for various logging frameworks such as java.util.logging (JUL) or Log4j. Currently, plugins are required to do all their logging using the provided JUL logger. This is annoying for plugins that target multiple platforms or when using libraries that log messages using SLF4J. Expose SLF4J as optional logging API for plugins, so they can use it without having to shade it in the plugin and going through several layers of logging abstraction.
Essentials uses a custom logger name ("Essentials") instead of the
plugin logger. Log messages are redirected to the plugin logger by
setting the parent of the "Essentials" logger to the plugin logger.
With our changes, the plugin logger is now also called "Essentials",
resulting in an infinite loop. Make sure plugins can't change the
parent of the plugin logger to avoid this.
Some plugins bypass the plugin logger and add the plugin prefix manually to the log message. Since they use other logger names (e.g. qualified class names) these would now also appear in the log. Disable the logger prefix for these plugins so the messages show up correctly.
|
Thanks, @Minecrell. |
SLF4J-over-Log4j2 is not needed anymore as of PaperMC/Paper#890
|
Noticed a plugin merging start-up logging verbose with world loading verbose on a single line whereas it didn't before. 2nd line in particular. Other than that, just EssentialsX whining. |
|
@mibby That's because DabCore does wonderful logging using The Essentials warning is unrelated but can be fixed easily in Essentials. I will try to submit a PR to fix it when I have time, but until then it's just a warning, nothing breaks due to it. |
SLF4J logging for plugins is a feature introduced in PaperMC/Paper#890. Plugins should be able to use SLF4J as alternative logging API. All that is necessary to make that work is a proper SLF4J adapter implementation. However, right now Glowstone includes the SLF4J implementation for Log4j 1.x, which isn't used in Glowstone at all. Include the correct SLF4J implementation for the java.util.logging API to make SLF4J logging work correctly.
SLF4J logging for plugins is a feature introduced in PaperMC/Paper#890. Plugins should be able to use SLF4J as alternative logging API. All that is necessary to make that work is a proper SLF4J adapter implementation. However, right now Glowstone includes the SLF4J implementation for Log4j 1.x, which isn't used in Glowstone at all. Include the correct SLF4J implementation for the java.util.logging API to make SLF4J logging work correctly.
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 5662c2b SPIGOT-6642: Throw better message if plugin.yml is empty aa8e035 PaperMC#636: Add FurnaceStartSmeltEvent 52073b3 SPIGOT-6646: Issue with map palette ranges 5f772da PaperMC#640: Add new Causes for LightningStrikeEvent CraftBukkit Changes: 4e18704 PaperMC#874: Add FurnaceStartSmeltEvent ed2b91c SPIGOT-6649: Call BlockFadeEvent when Nylium fades to Netherrack b7e3ce0 PaperMC#890: Include yaw in player's spawn location aeb711d PaperMC#889: Fix CraftChest close() sound being replaced with open sound. ca0fe5b SPIGOT-5561: Warning in logs when changing a Mob Spawner to Air on chunk load 2f038f2 PaperMC#886: Add new Causes for LightningStrikeEvent Spigot Changes: 38e6c03d Rebuild patches

This is a set of 3 commits to improve the logging implementation of Paper and allow plugins to use SLF4J as alternative logging API. The exact changes and the reasoning for them is explained in the commit messages (either directly or in the patches) so I'm not going to repeat everything here.
SLF4J is a commonly used abstraction for various logging frameworks and it is the easiest way to handle logging in an implementation-agnostic way. It is also used by many Java libraries as logging abstraction. I intend to create a similar PR for Waterfall so eventually, the same logging API can be used on Paper, Waterfall, Sponge and other modding APIs.
The primary difficulty to make this work was to move the plugin prefixes out of a custom JUL
PluginLoggerimplementation and handle them directly in the underlying logging framework (Log4J). Otherwise, messages logged with SLF4J would be missing the plugin prefix.The solution is pretty simple: Use the plugin name as logger name and make it visible in the log using the Log4J configuration. Hide the logger name for Minecraft and Paper log messages to make it less verbose.