For relying on SLF4J as a standard logging solution in a Bukkit environment (including forks like Spigot, PaperMC, ...).
Bukkit exposes a JUL logger,
built by itself
for each plugin individually.
Because of such setup, the slf4j-jdk14
bridge will work without taking into
account the custom Bukkit's log format.
The fact PaperMC exposes a
getSLF4JLogger()
method
doesn't really change anything.
While you may consider injecting the plugin's logger instance yourself in each place where one is required, this is not convenient nor applicable for any library relying purely on SLF4J like HikariCP.
This bridge handles for you the Bukkit's logger injection in each place where required, including libraries completely agnostic to Bukkit and/or any logging implementation. You just need to provide the Bukkit logger instance at plugin enabling time, and you are good to go!
Its implementation is inspired by the slf4j-jdk14 one.
The library is available in the Maven Central Repository.
<dependency>
<groupId>com.djaytan.bukkit</groupId>
<artifactId>bukkit-slf4j</artifactId>
<version>VERSION_HERE</version>
</dependency>
implementation group: 'com.djaytan.bukkit', name: 'bukkit-slf4j', version: 'VERSION_HERE'
Once added, you simply need to pass the Bukkit logger when enabling plugin like as follows:
public class YourPlugin extends JavaPlugin {
@Override
public void onEnable() {
// It's important to call this method as soon as possible, especially before loading any class
BukkitLoggerFactory.provideBukkitLogger(this.getLogger());
// Then execute your plugin's specific logic
}
}
Then you can declare a standard logger injection point as follows:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyClass {
// The bridge will inject the Bukkit logger automatically
private static final Logger log = LoggerFactory.getLogger(MyClass.class);
public void myMethod() {
log.info("Bukkit x SLF4J");
}
}
You can find a concrete example of Bukkit plugin using this extension here.
Please read CONTRIBUTING.md for details on ways to help us.
Take care to always follow our CODE_OF_CONDUCT.md.
We use SemVer for versioning. For the versions available, see the tags on this repository.
In case you think having found a security vulnerability, please consult our Security Policy.
This project is under the MIT license.