001package net.tnemc.plugincore.bukkit.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;
024
025import java.util.logging.Logger;
026
027/**
028 * BukkitLogProvider
029 *
030 * @author creatorfromhell
031 * @since 0.1.2.0
032 */
033public record BukkitLogProvider(Logger logger) implements LogProvider {
034
035  /**
036   * Sends an informative message, which doesn't contain an error or debug message.
037   *
038   * @param message The message to send.
039   * @param level   The {@link DebugLevel} to log this message at.
040   */
041  @Override
042  public void inform(String message, DebugLevel level) {
043    if(level.compare(PluginCore.instance().getLevel())) {
044      logger.info(message);
045    }
046  }
047
048  /**
049   * Sends a message related to debug purposes.
050   *
051   * @param message The message to send.
052   * @param level   The {@link DebugLevel} to log this message at.
053   */
054  @Override
055  public void debug(String message, DebugLevel level) {
056    if(level.compare(PluginCore.instance().getLevel())) {
057      logger.warning("[DEBUG]: " + message);
058    }
059  }
060
061  /**
062   * Sends a warning message.
063   *
064   * @param message The message to send.
065   * @param level   The {@link DebugLevel} to log this message at.
066   */
067  @Override
068  public void warning(String message, DebugLevel level) {
069    if(level.compare(PluginCore.instance().getLevel())) {
070      logger.warning(message);
071    }
072  }
073
074  /**
075   * Sends an error-related message.
076   *
077   * @param message The message to send.
078   * @param level   The {@link DebugLevel} to log this message at.
079   */
080  @Override
081  public void error(String message, DebugLevel level) {
082    if(level.compare(PluginCore.instance().getLevel())) {
083      logger.warning(message);
084    }
085  }
086
087  /**
088   * Sends an error-related message.
089   *
090   * @param message   The message to send.
091   * @param exception The error's {@link Exception}.
092   * @param level     The {@link DebugLevel} to log this message at.
093   */
094  @Override
095  public void error(String message, Exception exception, DebugLevel level) {
096    if(level.compare(PluginCore.instance().getLevel())) {
097      logger.warning("====== Exception Occurred ======");
098      exception.printStackTrace();
099      logger.warning("====== Please report this to someone ======");
100    }
101  }
102}