Stuff from the common floobits workspace
Author: AuthMe-Team <AuthMeTeam@123NoEmail.com>
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
@@ -8,12 +12,8 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
/**
|
||||
* The plugin's static logger.
|
||||
*/
|
||||
public class ConsoleLogger {
|
||||
|
||||
@@ -21,42 +21,52 @@ public class ConsoleLogger {
|
||||
private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||
|
||||
/**
|
||||
* Method info.
|
||||
* Returns the plugin's logger.
|
||||
*
|
||||
* @return Logger
|
||||
*/
|
||||
public static Logger getLogger() {
|
||||
return log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print an info message.
|
||||
*
|
||||
* @param message String
|
||||
*/
|
||||
public static void info(String message) {
|
||||
log.info("[AuthMe] " + message);
|
||||
if (Settings.useLogging) {
|
||||
String dateTime;
|
||||
synchronized (df) {
|
||||
dateTime = df.format(new Date());
|
||||
}
|
||||
writeLog(dateTime + " " + message);
|
||||
log.info(message);
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
}
|
||||
writeLog("" + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method showError.
|
||||
* Print an error message.
|
||||
*
|
||||
* @param message String
|
||||
*/
|
||||
public static void showError(String message) {
|
||||
log.warning("[AuthMe] " + message);
|
||||
if (Settings.useLogging) {
|
||||
String dateTime;
|
||||
synchronized (df) {
|
||||
dateTime = df.format(new Date());
|
||||
}
|
||||
writeLog(dateTime + " ERROR: " + message);
|
||||
log.warning(message);
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
}
|
||||
writeLog("ERROR: " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method writeLog.
|
||||
* Write a message into the log file with a TimeStamp.
|
||||
*
|
||||
* @param message String
|
||||
*/
|
||||
public static void writeLog(String message) {
|
||||
private static void writeLog(String message) {
|
||||
String dateTime;
|
||||
synchronized (df) {
|
||||
dateTime = df.format(new Date());
|
||||
}
|
||||
try {
|
||||
Files.write(Settings.LOG_FILE.toPath(), (message + NewAPI.newline).getBytes(),
|
||||
Files.write(Settings.LOG_FILE.toPath(), (dateTime + ": " + message + StringUtils.newline).getBytes(),
|
||||
StandardOpenOption.APPEND,
|
||||
StandardOpenOption.CREATE);
|
||||
} catch (IOException ignored) {
|
||||
@@ -64,16 +74,14 @@ public class ConsoleLogger {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method writeStackTrace.
|
||||
* Write a StackTrace into the log.
|
||||
*
|
||||
* @param ex Exception
|
||||
*/
|
||||
public static void writeStackTrace(Exception ex) {
|
||||
if (Settings.useLogging) {
|
||||
String dateTime;
|
||||
synchronized (df) {
|
||||
dateTime = df.format(new Date());
|
||||
}
|
||||
writeLog(dateTime + " " + Throwables.getStackTraceAsString(ex));
|
||||
if (!Settings.useLogging) {
|
||||
return;
|
||||
}
|
||||
writeLog("" + Throwables.getStackTraceAsString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user