mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-08 11:40:58 +01:00
#704 Reload settings of ConsoleLogger on /authme reload
This commit is contained in:
parent
92a8a5dd41
commit
14002ee75c
@ -44,16 +44,10 @@ import fr.xephi.authme.settings.SettingsMigrationService;
|
|||||||
import fr.xephi.authme.settings.SpawnLoader;
|
import fr.xephi.authme.settings.SpawnLoader;
|
||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
|
|
||||||
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_ACCOUNT;
|
|
||||||
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
|
||||||
import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
|
|
||||||
|
|
||||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.settings.properties.PurgeSettings;
|
import fr.xephi.authme.settings.properties.PurgeSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
|
||||||
import fr.xephi.authme.settings.properties.SettingsFieldRetriever;
|
import fr.xephi.authme.settings.properties.SettingsFieldRetriever;
|
||||||
import fr.xephi.authme.settings.propertymap.PropertyMap;
|
import fr.xephi.authme.settings.propertymap.PropertyMap;
|
||||||
import fr.xephi.authme.task.PurgeTask;
|
import fr.xephi.authme.task.PurgeTask;
|
||||||
@ -64,6 +58,17 @@ import fr.xephi.authme.util.GeoLiteAPI;
|
|||||||
import fr.xephi.authme.util.MigrationService;
|
import fr.xephi.authme.util.MigrationService;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -76,17 +81,9 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_ACCOUNT;
|
||||||
import org.bukkit.Bukkit;
|
import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
||||||
import org.bukkit.Location;
|
import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The AuthMe main class.
|
* The AuthMe main class.
|
||||||
@ -223,8 +220,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
getServer().shutdown();
|
getServer().shutdown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ConsoleLogger.setLoggingOptions(newSettings.getProperty(SecuritySettings.USE_LOGGING),
|
ConsoleLogger.setLogFile(new File(getDataFolder(), "authme.log"));
|
||||||
new File(getDataFolder(), "authme.log"));
|
ConsoleLogger.setLoggingOptions(newSettings);
|
||||||
|
|
||||||
// Old settings manager
|
// Old settings manager
|
||||||
if (!loadSettings()) {
|
if (!loadSettings()) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
|
||||||
@ -21,22 +22,26 @@ public final class ConsoleLogger {
|
|||||||
private static final String NEW_LINE = System.getProperty("line.separator");
|
private static final String NEW_LINE = System.getProperty("line.separator");
|
||||||
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||||
private static Logger logger;
|
private static Logger logger;
|
||||||
|
private static boolean enableDebug = false;
|
||||||
private static boolean useLogging = false;
|
private static boolean useLogging = false;
|
||||||
private static File logFile;
|
private static File logFile;
|
||||||
|
|
||||||
private ConsoleLogger() {
|
private ConsoleLogger() {
|
||||||
// Service class
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLogger(Logger logger) {
|
public static void setLogger(Logger logger) {
|
||||||
ConsoleLogger.logger = logger;
|
ConsoleLogger.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLoggingOptions(boolean useLogging, File logFile) {
|
public static void setLogFile(File logFile) {
|
||||||
ConsoleLogger.useLogging = useLogging;
|
|
||||||
ConsoleLogger.logFile = logFile;
|
ConsoleLogger.logFile = logFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setLoggingOptions(NewSetting settings) {
|
||||||
|
ConsoleLogger.useLogging = settings.getProperty(SecuritySettings.USE_LOGGING);
|
||||||
|
ConsoleLogger.enableDebug = !settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print an info message.
|
* Print an info message.
|
||||||
*
|
*
|
||||||
@ -50,7 +55,7 @@ public final class ConsoleLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(String message) {
|
public static void debug(String message) {
|
||||||
if (!AuthMe.getInstance().getSettings().getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
|
if (enableDebug) {
|
||||||
logger.fine(message);
|
logger.fine(message);
|
||||||
if (useLogging) {
|
if (useLogging) {
|
||||||
writeLog("Debug: " + message);
|
writeLog("Debug: " + message);
|
||||||
|
@ -40,6 +40,7 @@ public class ReloadCommand implements ExecutableCommand {
|
|||||||
ConsoleLogger.info("Note: cannot change database type during /authme reload");
|
ConsoleLogger.info("Note: cannot change database type during /authme reload");
|
||||||
sender.sendMessage("Note: cannot change database type during /authme reload");
|
sender.sendMessage("Note: cannot change database type during /authme reload");
|
||||||
}
|
}
|
||||||
|
ConsoleLogger.setLoggingOptions(settings);
|
||||||
initializer.performReloadOnServices();
|
initializer.performReloadOnServices();
|
||||||
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -9,7 +9,9 @@ import fr.xephi.authme.initialization.AuthMeServiceInitializer;
|
|||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.settings.NewSetting;
|
import fr.xephi.authme.settings.NewSetting;
|
||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -53,6 +55,13 @@ public class ReloadCommandTest {
|
|||||||
TestHelper.setupLogger();
|
TestHelper.setupLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setDefaultSettings() {
|
||||||
|
// Mock properties retrieved by ConsoleLogger
|
||||||
|
given(settings.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)).willReturn(false);
|
||||||
|
given(settings.getProperty(SecuritySettings.USE_LOGGING)).willReturn(false);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReload() {
|
public void shouldReload() {
|
||||||
// given
|
// given
|
||||||
|
Loading…
Reference in New Issue
Block a user