* #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:
@@ -9,6 +9,7 @@ import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.datasource.PostgreSqlDataSource;
|
||||
import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.datasource.mysqlextensions.MySqlExtensionsFactory;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
@@ -16,7 +17,6 @@ import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
@@ -26,6 +26,8 @@ public class DataSourceProvider implements Provider<DataSource> {
|
||||
|
||||
private static final int SQLITE_MAX_SIZE = 4000;
|
||||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(DataSourceProvider.class);
|
||||
|
||||
@Inject
|
||||
@DataFolder
|
||||
private File dataFolder;
|
||||
@@ -46,7 +48,7 @@ public class DataSourceProvider implements Provider<DataSource> {
|
||||
try {
|
||||
return createDataSource();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Could not create data source:", e);
|
||||
logger.logException("Could not create data source:", e);
|
||||
throw new IllegalStateException("Error during initialization of data source", e);
|
||||
}
|
||||
}
|
||||
@@ -54,11 +56,10 @@ public class DataSourceProvider implements Provider<DataSource> {
|
||||
/**
|
||||
* Sets up the data source.
|
||||
*
|
||||
* @return the constructed datasource
|
||||
* @throws SQLException when initialization of a SQL datasource failed
|
||||
* @throws IOException if flat file cannot be read
|
||||
* @return the constructed data source
|
||||
* @throws SQLException when initialization of a SQL data source failed
|
||||
*/
|
||||
private DataSource createDataSource() throws SQLException, IOException {
|
||||
private DataSource createDataSource() throws SQLException {
|
||||
DataSourceType dataSourceType = settings.getProperty(DatabaseSettings.BACKEND);
|
||||
DataSource dataSource;
|
||||
switch (dataSourceType) {
|
||||
@@ -88,7 +89,7 @@ public class DataSourceProvider implements Provider<DataSource> {
|
||||
bukkitService.runTaskAsynchronously(() -> {
|
||||
int accounts = dataSource.getAccountsRegistered();
|
||||
if (accounts >= SQLITE_MAX_SIZE) {
|
||||
ConsoleLogger.warning("YOU'RE USING THE SQLITE DATABASE WITH "
|
||||
logger.warning("YOU'RE USING THE SQLITE DATABASE WITH "
|
||||
+ accounts + "+ ACCOUNTS; FOR BETTER PERFORMANCE, PLEASE UPGRADE TO MYSQL!!");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ package fr.xephi.authme.initialization;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.output.ConsoleFilter;
|
||||
@@ -28,6 +29,8 @@ import static fr.xephi.authme.settings.properties.EmailSettings.RECALL_PLAYERS;
|
||||
*/
|
||||
public class OnStartupTasks {
|
||||
|
||||
private static ConsoleLogger consoleLogger = ConsoleLoggerFactory.get(OnStartupTasks.class);
|
||||
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
@Inject
|
||||
@@ -58,17 +61,16 @@ public class OnStartupTasks {
|
||||
/**
|
||||
* Sets up the console filter if enabled.
|
||||
*
|
||||
* @param settings the settings
|
||||
* @param logger the plugin logger
|
||||
* @param logger the plugin logger
|
||||
*/
|
||||
public static void setupConsoleFilter(Settings settings, Logger logger) {
|
||||
public static void setupConsoleFilter(Logger logger) {
|
||||
// Try to set the log4j filter
|
||||
try {
|
||||
Class.forName("org.apache.logging.log4j.core.filter.AbstractFilter");
|
||||
setLog4JFilter();
|
||||
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
||||
// log4j is not available
|
||||
ConsoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support will be disabled");
|
||||
consoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support will be disabled");
|
||||
ConsoleFilter filter = new ConsoleFilter();
|
||||
logger.setFilter(filter);
|
||||
Bukkit.getLogger().setFilter(filter);
|
||||
|
||||
Reference in New Issue
Block a user