Skip to content

Djaytan/bukkit-slf4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bukkit SLF4J Bridge

Maven metadata URL CI semantic-release: conventional-commits
Quality Gate Status Coverage OpenSSF Best Practices OpenSSF Scorecard
FOSSA Status

SLF4J bridge to Bukkit's logger for plugins.

Why Using It?

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.

Setup

The library is available in the Maven Central Repository.

Maven

<dependency>
  <groupId>com.djaytan.bukkit</groupId>
  <artifactId>bukkit-slf4j</artifactId>
  <version>VERSION_HERE</version>
</dependency>

Gradle

implementation group: 'com.djaytan.bukkit', name: 'bukkit-slf4j', version: 'VERSION_HERE'

How To Use

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.

Contributing

Please read CONTRIBUTING.md for details on ways to help us.

Take care to always follow our CODE_OF_CONDUCT.md.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Security Policy

In case you think having found a security vulnerability, please consult our Security Policy.

Licence

This project is under the MIT license.

FOSSA Status