001package net.tnemc.plugincore.sponge.impl;
002
003/*
004 * The New Plugin Core
005 * Copyright (C) 2022 - 2024 Daniel "creatorfromhell" Vidmar
006 *
007 * This program is free software: you can redistribute it and/or modify
008 * it under the terms of the GNU Affero General Public License as published by
009 * the Free Software Foundation, either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015 * GNU Affero General Public License for more details.
016 *
017 * You should have received a copy of the GNU Affero General Public License
018 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
019 */
020
021import net.tnemc.plugincore.PluginCore;
022import net.tnemc.plugincore.core.compatibility.LogProvider;
023import net.tnemc.plugincore.core.compatibility.log.DebugLevel;
024import org.apache.logging.log4j.Logger;
025
026/**
027 * SpongeLogProvider
028 *
029 * @author creatorfromhell
030 * @since 0.1.2.0
031 */
032public record SpongeLogProvider(Logger logger) implements LogProvider {
033
034  /**
035   * Sends an informative message, which doesn't contain an error or debug message.
036   *
037   * @param message The message to send.
038   * @param level   The {@link DebugLevel} to log this message at.
039   */
040  @Override
041  public void inform(String message, DebugLevel level) {
042    if(level.compare(PluginCore.instance().getLevel())) {
043      logger.info(message);
044    }
045  }
046
047  /**
048   * Sends a message related to debug purposes.
049   *
050   * @param message The message to send.
051   * @param level   The {@link DebugLevel} to log this message at.
052   */
053  @Override
054  public void debug(String message, DebugLevel level) {
055    if(level.compare(PluginCore.instance().getLevel())) {
056      logger.debug(message);
057    }
058  }
059
060  /**
061   * Sends a warning message.
062   *
063   * @param message The message to send.
064   * @param level   The {@link DebugLevel} to log this message at.
065   */
066  @Override
067  public void warning(String message, DebugLevel level) {
068    if(level.compare(PluginCore.instance().getLevel())) {
069      logger.warn(message);
070    }
071  }
072
073  /**
074   * Sends an error-related message.
075   *
076   * @param message The message to send.
077   * @param level   The {@link DebugLevel} to log this message at.
078   */
079  @Override
080  public void error(String message, DebugLevel level) {
081    if(level.compare(PluginCore.instance().getLevel())) {
082      logger.error(message);
083    }
084  }
085
086  /**
087   * Sends an error-related message.
088   *
089   * @param message   The message to send.
090   * @param exception The error's {@link Exception}.
091   * @param level     The {@link DebugLevel} to log this message at.
092   */
093  @Override
094  public void error(String message, Exception exception, DebugLevel level) {
095    if(level.compare(PluginCore.instance().getLevel())) {
096      logger.error("====== Exception Occurred ======");
097      exception.printStackTrace();
098      logger.error("====== Please report this to someone ======");
099    }
100  }
101}