* #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:
@@ -3,6 +3,7 @@ package fr.xephi.authme.util;
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -20,6 +21,8 @@ public final class FileUtils {
|
||||
private static final DateTimeFormatter CURRENT_DATE_STRING_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyyMMdd_HHmm");
|
||||
|
||||
private static ConsoleLogger logger = ConsoleLoggerFactory.get(FileUtils.class);
|
||||
|
||||
// Utility class
|
||||
private FileUtils() {
|
||||
}
|
||||
@@ -36,20 +39,20 @@ public final class FileUtils {
|
||||
if (destinationFile.exists()) {
|
||||
return true;
|
||||
} else if (!createDirectory(destinationFile.getParentFile())) {
|
||||
ConsoleLogger.warning("Cannot create parent directories for '" + destinationFile + "'");
|
||||
logger.warning("Cannot create parent directories for '" + destinationFile + "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
try (InputStream is = getResourceFromJar(resourcePath)) {
|
||||
if (is == null) {
|
||||
ConsoleLogger.warning(format("Cannot copy resource '%s' to file '%s': cannot load resource",
|
||||
logger.warning(format("Cannot copy resource '%s' to file '%s': cannot load resource",
|
||||
resourcePath, destinationFile.getPath()));
|
||||
} else {
|
||||
java.nio.file.Files.copy(is, destinationFile.toPath());
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.logException(format("Cannot copy resource '%s' to file '%s':",
|
||||
logger.logException(format("Cannot copy resource '%s' to file '%s':",
|
||||
resourcePath, destinationFile.getPath()), e);
|
||||
}
|
||||
return false;
|
||||
@@ -63,7 +66,7 @@ public final class FileUtils {
|
||||
*/
|
||||
public static boolean createDirectory(File dir) {
|
||||
if (!dir.exists() && !dir.mkdirs()) {
|
||||
ConsoleLogger.warning("Could not create directory '" + dir + "'");
|
||||
logger.warning("Could not create directory '" + dir + "'");
|
||||
return false;
|
||||
}
|
||||
return dir.isDirectory();
|
||||
@@ -112,7 +115,7 @@ public final class FileUtils {
|
||||
if (file != null) {
|
||||
boolean result = file.delete();
|
||||
if (!result) {
|
||||
ConsoleLogger.warning("Could not delete file '" + file + "'");
|
||||
logger.warning("Could not delete file '" + file + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
@@ -15,8 +16,8 @@ public final class Utils {
|
||||
|
||||
/** Number of milliseconds in a minute. */
|
||||
public static final long MILLIS_PER_MINUTE = 60_000L;
|
||||
/** Number of milliseconds in an hour. */
|
||||
public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
|
||||
|
||||
private static ConsoleLogger logger = ConsoleLoggerFactory.get(Utils.class);
|
||||
|
||||
// Utility class
|
||||
private Utils() {
|
||||
@@ -33,7 +34,7 @@ public final class Utils {
|
||||
try {
|
||||
return Pattern.compile(pattern);
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.warning("Failed to compile pattern '" + pattern + "' - defaulting to allowing everything");
|
||||
logger.warning("Failed to compile pattern '" + pattern + "' - defaulting to allowing everything");
|
||||
return Pattern.compile(".*?");
|
||||
}
|
||||
}
|
||||
@@ -63,7 +64,7 @@ public final class Utils {
|
||||
* @param message the message to log and send
|
||||
*/
|
||||
public static void logAndSendMessage(CommandSender sender, String message) {
|
||||
ConsoleLogger.info(message);
|
||||
logger.info(message);
|
||||
// Make sure sender is not console user, which will see the message from ConsoleLogger already
|
||||
if (sender != null && !(sender instanceof ConsoleCommandSender)) {
|
||||
sender.sendMessage(message);
|
||||
@@ -79,7 +80,7 @@ public final class Utils {
|
||||
* @param message the warning to log and send
|
||||
*/
|
||||
public static void logAndSendWarning(CommandSender sender, String message) {
|
||||
ConsoleLogger.warning(message);
|
||||
logger.warning(message);
|
||||
// Make sure sender is not console user, which will see the message from ConsoleLogger already
|
||||
if (sender != null && !(sender instanceof ConsoleCommandSender)) {
|
||||
sender.sendMessage(ChatColor.RED + message);
|
||||
|
||||
Reference in New Issue
Block a user