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(final String message, final DebugLevel level) { 043 044 if(level.compare(PluginCore.instance().getLevel())) { 045 logger.info(message); 046 } 047 } 048 049 /** 050 * Sends a message related to debug purposes. 051 * 052 * @param message The message to send. 053 * @param level The {@link DebugLevel} to log this message at. 054 */ 055 @Override 056 public void debug(final String message, final DebugLevel level) { 057 058 if(level.compare(PluginCore.instance().getLevel())) { 059 logger.warning("[DEBUG]: " + message); 060 } 061 } 062 063 /** 064 * Sends a warning message. 065 * 066 * @param message The message to send. 067 * @param level The {@link DebugLevel} to log this message at. 068 */ 069 @Override 070 public void warning(final String message, final DebugLevel level) { 071 072 if(level.compare(PluginCore.instance().getLevel())) { 073 logger.warning(message); 074 } 075 } 076 077 /** 078 * Sends an error-related message. 079 * 080 * @param message The message to send. 081 * @param level The {@link DebugLevel} to log this message at. 082 */ 083 @Override 084 public void error(final String message, final DebugLevel level) { 085 086 if(level.compare(PluginCore.instance().getLevel())) { 087 logger.warning(message); 088 } 089 } 090 091 /** 092 * Sends an error-related message. 093 * 094 * @param message The message to send. 095 * @param exception The error's {@link Exception}. 096 * @param level The {@link DebugLevel} to log this message at. 097 */ 098 @Override 099 public void error(final String message, final Exception exception, final DebugLevel level) { 100 101 if(level.compare(PluginCore.instance().getLevel())) { 102 logger.warning("====== Exception Occurred ======"); 103 exception.printStackTrace(); 104 logger.warning("====== Please report this to someone ======"); 105 } 106 } 107}