001package net.tnemc.plugincore.core.compatibility;
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.core.compatibility.log.DebugLevel;
022
023/**
024 * Provides a compatibility layer for logging purposes.
025 *
026 * @since 0.1.2.0
027 * @author creatorfromhell
028 */
029public interface LogProvider {
030
031  /**
032   * Sends an informative message, which doesn't contain an error or debug message.
033   * @param message The message to send.
034   */
035  default void inform(String message) {
036    inform(message, DebugLevel.STANDARD);
037  }
038
039  /**
040   * Sends an informative message, which doesn't contain an error or debug message.
041   * @param message The message to send.
042   * @param level The {@link DebugLevel} to log this message at.
043   */
044  void inform(String message, DebugLevel level);
045
046  /**
047   * Sends a message related to debug purposes.
048   * @param message The message to send.
049   */
050  default void debug(String message) {
051    debug(message, DebugLevel.STANDARD);
052  }
053
054  /**
055   * Sends a message related to debug purposes.
056   * @param message The message to send.
057   * @param level The {@link DebugLevel} to log this message at.
058   */
059  void debug(String message, DebugLevel level);
060
061  /**
062   * Sends a warning message.
063   * @param message The message to send.
064   */
065  default void warning(String message) {
066    warning(message, DebugLevel.STANDARD);
067  }
068
069  /**
070   * Sends a warning message.
071   * @param message The message to send.
072   * @param level The {@link DebugLevel} to log this message at.
073   */
074  void warning(String message, DebugLevel level);
075
076  /**
077   * Sends an error-related message.
078   * @param message The message to send.
079   */
080  default void error(String message) {
081    error(message, DebugLevel.STANDARD);
082  }
083
084  /**
085   * Sends an error-related message.
086   * @param message The message to send.
087   * @param level The {@link DebugLevel} to log this message at.
088   */
089  void error(String message, DebugLevel level);
090
091  /**
092   * Sends an error-related message.
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  void error(String message, Exception exception, DebugLevel level);
098
099
100  /**
101   * Sends an error that is SQL-related.
102   * @param message The message to send.
103   * @param exception The error's {@link Exception}.
104   * @param query The query string.
105   * @param variables An array of variables for the prepared statement.
106   * @param level The {@link DebugLevel} to log this message at.
107   */
108  default void sqlError(String message, Exception exception, String query, Object[] variables, DebugLevel level) {
109    error("======= Query Error =======", level);
110    error(message, exception, level);
111
112    error("======= Query Statement =======", level);
113    error(query, level);
114    error("======= Query Variables Statement =======", level);
115
116    for(int i = 0; i < variables.length; i++) {
117      error("Variable - " + variables[i], level);
118    }
119    error("======= End Query Statement =======", level);
120  }
121}