#1874 Introduce individual ConsoleLogger instance per class (#1875)

* #1874 Introduce individual ConsoleLogger instance per class
- Create ConsoleLoggerFactory from which a separate logger can be created for each class
- Allows to support individual log level settings in the future

* Fix CodeStyle issue

* Replace full class name with import

* Update usages after merge from master
This commit is contained in:
ljacqu
2019-08-06 15:15:16 +02:00
committed by Gabriele C
parent 254d4d75a2
commit c34f00f759
98 changed files with 853 additions and 387 deletions
@@ -6,6 +6,7 @@ import ch.jalu.configme.migration.MigrationService;
import ch.jalu.configme.resource.PropertyResource;
import com.google.common.io.Files;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import java.io.File;
import java.io.IOException;
@@ -18,6 +19,7 @@ import static fr.xephi.authme.util.FileUtils.copyFileFromResource;
*/
public class Settings extends SettingsManagerImpl {
private final ConsoleLogger logger = ConsoleLoggerFactory.get(Settings.class);
private final File pluginFolder;
private String passwordEmailMessage;
private String verificationEmailMessage;
@@ -89,10 +91,10 @@ public class Settings extends SettingsManagerImpl {
try {
return Files.asCharSource(file, StandardCharsets.UTF_8).read();
} catch (IOException e) {
ConsoleLogger.logException("Failed to read file '" + filename + "':", e);
logger.logException("Failed to read file '" + filename + "':", e);
}
} else {
ConsoleLogger.warning("Failed to copy file '" + filename + "' from JAR");
logger.warning("Failed to copy file '" + filename + "' from JAR");
}
return "";
}
@@ -6,6 +6,7 @@ import ch.jalu.configme.properties.Property;
import ch.jalu.configme.resource.PropertyReader;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.output.LogLevel;
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
import fr.xephi.authme.process.register.RegistrationType;
@@ -38,7 +39,8 @@ import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAW
* Service for verifying that the configuration is up-to-date.
*/
public class SettingsMigrationService extends PlainMigrationService {
private static ConsoleLogger logger = ConsoleLoggerFactory.get(SettingsMigrationService.class);
private final File pluginFolder;
// Stores old "other accounts command" config if present.
@@ -141,7 +143,7 @@ public class SettingsMigrationService extends PlainMigrationService {
try (FileWriter fw = new FileWriter(emailFile)) {
fw.write(mailText);
} catch (IOException e) {
ConsoleLogger.logException("Could not create email.html configuration file:", e);
logger.logException("Could not create email.html configuration file:", e);
}
}
return true;
@@ -160,7 +162,7 @@ public class SettingsMigrationService extends PlainMigrationService {
boolean hasMigrated = moveProperty(oldDelayJoinProperty, DELAY_JOIN_MESSAGE, reader, configData);
if (hasMigrated) {
ConsoleLogger.info(String.format("Note that we now also have the settings %s and %s",
logger.info(String.format("Note that we now also have the settings %s and %s",
REMOVE_JOIN_MESSAGE.getPath(), REMOVE_LEAVE_MESSAGE.getPath()));
}
return hasMigrated;
@@ -213,7 +215,7 @@ public class SettingsMigrationService extends PlainMigrationService {
final String oldPath = "Security.console.noConsoleSpam";
final Property<LogLevel> newProperty = PluginSettings.LOG_LEVEL;
if (!newProperty.isPresent(reader) && reader.contains(oldPath)) {
ConsoleLogger.info("Moving '" + oldPath + "' to '" + newProperty.getPath() + "'");
logger.info("Moving '" + oldPath + "' to '" + newProperty.getPath() + "'");
boolean oldValue = Optional.ofNullable(reader.getBoolean(oldPath)).orElse(false);
LogLevel level = oldValue ? LogLevel.INFO : LogLevel.FINE;
configData.setValue(newProperty, level);
@@ -224,7 +226,7 @@ public class SettingsMigrationService extends PlainMigrationService {
private static boolean hasOldHelpHeaderProperty(PropertyReader reader) {
if (reader.contains("settings.helpHeader")) {
ConsoleLogger.warning("Help header setting is now in messages/help_xx.yml, "
logger.warning("Help header setting is now in messages/help_xx.yml, "
+ "please check the file to set it again");
return true;
}
@@ -234,7 +236,7 @@ public class SettingsMigrationService extends PlainMigrationService {
private static boolean hasSupportOldPasswordProperty(PropertyReader reader) {
String path = "settings.security.supportOldPasswordHash";
if (reader.contains(path)) {
ConsoleLogger.warning("Property '" + path + "' is no longer supported. "
logger.warning("Property '" + path + "' is no longer supported. "
+ "Use '" + SecuritySettings.LEGACY_HASHES.getPath() + "' instead.");
return true;
}
@@ -265,7 +267,7 @@ public class SettingsMigrationService extends PlainMigrationService {
? RegisterSecondaryArgument.CONFIRMATION
: RegisterSecondaryArgument.NONE;
ConsoleLogger.warning("Merging old registration settings into '"
logger.warning("Merging old registration settings into '"
+ RegistrationSettings.REGISTRATION_TYPE.getPath() + "'");
configData.setValue(RegistrationSettings.REGISTRATION_TYPE, registrationType);
configData.setValue(RegistrationSettings.REGISTER_SECOND_ARGUMENT, secondaryArgument);
@@ -318,7 +320,7 @@ public class SettingsMigrationService extends PlainMigrationService {
Set<HashAlgorithm> legacyHashes = SecuritySettings.LEGACY_HASHES.determineValue(reader);
legacyHashes.add(currentHash);
configData.setValue(SecuritySettings.LEGACY_HASHES, legacyHashes);
ConsoleLogger.warning("The hash algorithm '" + currentHash
logger.warning("The hash algorithm '" + currentHash
+ "' is no longer supported for active use. New hashes will be in SHA256.");
return true;
}
@@ -372,9 +374,9 @@ public class SettingsMigrationService extends PlainMigrationService {
ConfigurationData configData) {
if (reader.contains(oldProperty.getPath())) {
if (reader.contains(newProperty.getPath())) {
ConsoleLogger.info("Detected deprecated property " + oldProperty.getPath());
logger.info("Detected deprecated property " + oldProperty.getPath());
} else {
ConsoleLogger.info("Renaming " + oldProperty.getPath() + " to " + newProperty.getPath());
logger.info("Renaming " + oldProperty.getPath() + " to " + newProperty.getPath());
configData.setValue(newProperty, oldProperty.determineValue(reader));
}
return true;
@@ -2,6 +2,7 @@ package fr.xephi.authme.settings;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.security.crypts.Argon2;
import fr.xephi.authme.service.BukkitService;
@@ -22,6 +23,8 @@ import java.util.Optional;
* see {@link SettingsMigrationService}.
*/
public class SettingsWarner {
private final ConsoleLogger logger = ConsoleLoggerFactory.get(SettingsWarner.class);
@Inject
private Settings settings;
@@ -41,25 +44,25 @@ public class SettingsWarner {
public void logWarningsForMisconfigurations() {
// Force single session disabled
if (!settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)) {
ConsoleLogger.warning("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!");
logger.warning("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!");
}
// Use TLS property only affects port 25
if (!settings.getProperty(EmailSettings.PORT25_USE_TLS)
&& settings.getProperty(EmailSettings.SMTP_PORT) != 25) {
ConsoleLogger.warning("Note: You have set Email.useTls to false but this only affects mail over port 25");
logger.warning("Note: You have set Email.useTls to false but this only affects mail over port 25");
}
// Output hint if sessions are enabled that the timeout must be positive
if (settings.getProperty(PluginSettings.SESSIONS_ENABLED)
&& settings.getProperty(PluginSettings.SESSIONS_TIMEOUT) <= 0) {
ConsoleLogger.warning("Warning: Session timeout needs to be positive in order to work!");
logger.warning("Warning: Session timeout needs to be positive in order to work!");
}
// Warn if spigot.yml has settings.bungeecord set to true but config.yml has Hooks.bungeecord set to false
if (isTrue(bukkitService.isBungeeCordConfiguredForSpigot())
&& !settings.getProperty(HooksSettings.BUNGEECORD)) {
ConsoleLogger.warning("Note: Hooks.bungeecord is set to false but your server appears to be running in"
logger.warning("Note: Hooks.bungeecord is set to false but your server appears to be running in"
+ " bungeecord mode (see your spigot.yml). In order to allow the datasource caching and the"
+ " AuthMeBungee add-on to work properly you have to enable this option!");
}
@@ -67,7 +70,7 @@ public class SettingsWarner {
// Check if argon2 library is present and can be loaded
if (settings.getProperty(SecuritySettings.PASSWORD_HASH).equals(HashAlgorithm.ARGON2)
&& !Argon2.isLibraryLoaded()) {
ConsoleLogger.warning("WARNING!!! You use Argon2 Hash Algorithm method but we can't find the Argon2 "
logger.warning("WARNING!!! You use Argon2 Hash Algorithm method but we can't find the Argon2 "
+ "library on your system! See https://github.com/AuthMe/AuthMeReloaded/wiki/Argon2-as-Password-Hash");
authMe.stopOrUnload();
}
@@ -3,6 +3,7 @@ package fr.xephi.authme.settings;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.service.PluginHookService;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
@@ -29,6 +30,8 @@ import java.io.IOException;
*/
public class SpawnLoader implements Reloadable {
private final ConsoleLogger logger = ConsoleLoggerFactory.get(SpawnLoader.class);
private final File authMeConfigurationFile;
private final Settings settings;
private final PluginHookService pluginHookService;
@@ -120,7 +123,7 @@ public class SpawnLoader implements Reloadable {
YamlConfiguration.loadConfiguration(essentialsSpawnFile), "spawns.default");
} else {
essentialsSpawn = null;
ConsoleLogger.info("Essentials spawn file not found: '" + essentialsSpawnFile.getAbsolutePath() + "'");
logger.info("Essentials spawn file not found: '" + essentialsSpawnFile.getAbsolutePath() + "'");
}
}
@@ -145,7 +148,7 @@ public class SpawnLoader implements Reloadable {
cmiSpawn = getLocationFromCmiConfiguration(YamlConfiguration.loadConfiguration(cmiConfig));
} else {
cmiSpawn = null;
ConsoleLogger.info("CMI config file not found: '" + cmiConfig.getAbsolutePath() + "'");
logger.info("CMI config file not found: '" + cmiConfig.getAbsolutePath() + "'");
}
}
@@ -198,11 +201,11 @@ public class SpawnLoader implements Reloadable {
// ignore
}
if (spawnLoc != null) {
ConsoleLogger.debug("Spawn location determined as `{0}` for world `{1}`", spawnLoc, world.getName());
logger.debug("Spawn location determined as `{0}` for world `{1}`", spawnLoc, world.getName());
return spawnLoc;
}
}
ConsoleLogger.debug("Fall back to default world spawn location. World: `{0}`", world.getName());
logger.debug("Fall back to default world spawn location. World: `{0}`", world.getName());
return world.getSpawnLocation(); // return default location
}
@@ -232,7 +235,7 @@ public class SpawnLoader implements Reloadable {
authMeConfiguration.save(authMeConfigurationFile);
return true;
} catch (IOException e) {
ConsoleLogger.logException("Could not save spawn config (" + authMeConfigurationFile + ")", e);
logger.logException("Could not save spawn config (" + authMeConfigurationFile + ")", e);
}
return false;
}
@@ -4,6 +4,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.GeoIpService;
@@ -35,6 +36,8 @@ import static fr.xephi.authme.util.lazytags.TagBuilder.createTag;
* Configuration for the welcome message (welcome.txt).
*/
public class WelcomeMessageConfiguration implements Reloadable {
private final ConsoleLogger logger = ConsoleLoggerFactory.get(WelcomeMessageConfiguration.class);
@DataFolder
@Inject
@@ -125,10 +128,10 @@ public class WelcomeMessageConfiguration implements Reloadable {
try {
return Files.readAllLines(welcomeFile.toPath(), StandardCharsets.UTF_8);
} catch (IOException e) {
ConsoleLogger.logException("Failed to read welcome.txt file:", e);
logger.logException("Failed to read welcome.txt file:", e);
}
} else {
ConsoleLogger.warning("Failed to copy welcome.txt from JAR");
logger.warning("Failed to copy welcome.txt from JAR");
}
return Collections.emptyList();
}