mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-11 06:38:00 +02:00
update ConsoleLogger
This commit is contained in:
parent
e406a7b21c
commit
e1b2a1852c
@ -1,33 +1,27 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import fr.xephi.authme.api.NewAPI;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ConsoleLogger {
|
||||
|
||||
private static final Logger log = Logger.getLogger("AuthMe");
|
||||
private static final Logger log = AuthMe.getInstance().getLogger();
|
||||
private static final DateFormat format = DateFormat.getDateTimeInstance();
|
||||
|
||||
|
||||
public static void info(String message) {
|
||||
if (AuthMe.getInstance().isEnabled()) {
|
||||
log.info("[AuthMe] " + message);
|
||||
if (Settings.useLogging) {
|
||||
Calendar date = Calendar.getInstance();
|
||||
final String actually = "[" + DateFormat.getDateInstance().format(date.getTime()) + ", " + date.get(Calendar.HOUR_OF_DAY) + ":" + date.get(Calendar.MINUTE) + ":" + date.get(Calendar.SECOND) + "] " + message;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AuthMe.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
writeLog(actually);
|
||||
}
|
||||
});
|
||||
writeLog("[" + format.format(new Date()) + "] " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -36,31 +30,21 @@ public class ConsoleLogger {
|
||||
if (AuthMe.getInstance().isEnabled()) {
|
||||
log.warning("[AuthMe] " + message);
|
||||
if (Settings.useLogging) {
|
||||
Calendar date = Calendar.getInstance();
|
||||
final String actually = "[" + DateFormat.getDateInstance().format(date.getTime()) + ", " + date.get(Calendar.HOUR_OF_DAY) + ":" + date.get(Calendar.MINUTE) + ":" + date.get(Calendar.SECOND) + "] ERROR : " + message;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AuthMe.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
writeLog(actually);
|
||||
}
|
||||
});
|
||||
writeLog("[" + format.format(new Date()) + "] ERROR: " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeLog(String string) {
|
||||
public static void writeLog(String message) {
|
||||
try {
|
||||
FileWriter fw = new FileWriter(AuthMe.getInstance().getDataFolder() + File.separator + "authme.log", true);
|
||||
BufferedWriter w = new BufferedWriter(fw);
|
||||
w.write(string);
|
||||
w.newLine();
|
||||
w.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Files.write(Settings.LOG_FILE.toPath(), (message + NewAPI.newline).getBytes(),
|
||||
StandardOpenOption.APPEND,
|
||||
StandardOpenOption.CREATE);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeStackTrace(Exception ex){
|
||||
public static void writeStackTrace(Exception ex) {
|
||||
writeLog(Throwables.getStackTraceAsString(ex));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user