slf4j?

Discussion in 'Plugin Development' started by lumpynose, Feb 16, 2024.

Thread Status:
Not open for further replies.
  1. Offline

    lumpynose

    Can I use slf4j instead of JavaPlugin's getLogger? In my pom.xml I have the following (note the provided for slf4j) and it seems to work with my test Paper server.

    Code:
        <dependencies>
            <dependency>
                <groupId>org.spigotmc</groupId>
                <artifactId>spigot-api</artifactId>
                <version>1.20.4-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>2.0.12</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    
     
  2. Online

    timtower Administrator Administrator Moderator

    Why do you want to do that?
     
  3. Offline

    lumpynose

    1: slf4j is what I've always used. 2: there are some conveniences with it; for example its curly braces thing;

    Code:
            } catch (ClassNotFoundException | SQLException e) {
                log.error("database creation failed: {}", e);
    
    In the above it prints the stack trace for the exception. Also
    Code:
            log.info("player: {}, event: {}", playerName, eventName);
    
    where playerName and eventName could be anything, not just String.
     
    Last edited: Feb 16, 2024
  4. Online

    timtower Administrator Administrator Moderator

    @lumpynose Doesn't a secundary logger conflict with the base one?
     
  5. Offline

    lumpynose

    It's a front end/wrapper for whatever logger is being used. The F in its name stands for facade. See its page, slf4j.org. It figures out what logging framework is being used and hooks into it (forwards to it). Since I specified the scope as provided, same as spigot-api, that means the slf4-api jar is being pulled in by someone else. Let me see if I can figure out who is doing that.

    Hmm, they all know about its goodness, so to speak. In my plugins folder I also have floodgate-spigot.jar and Geyser-spigot.jar, so that I can connect from my Switch, and they both show slf4j when I do an "unzip -l <name>.jar|grep slf4j". Going up a level and running that on paper.jar also shows slf4j. The other jars I happen to have laying around are minecraft_server.1.20.4.jar, purpur-1.20.4-2141.jar, and spigot-1.20.4.jar and they also show slf4j in them.

    I should have done all this before asking here. I'm guessing that all forks of the minecraft.net server use it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 17, 2024
  6. Online

    timtower Administrator Administrator Moderator

    If the original doesn't run it
     
Thread Status:
Not open for further replies.

Share This Page