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