mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-21 22:08:48 +00:00
feat: 日志记录添加配置开关
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
5f3db15b41
commit
bc20088f0f
@ -125,7 +125,7 @@ public class CommandInjector implements TabExecutor {
|
||||
sender.sendMessage("§6异常说明: §3" + e.getMessage());
|
||||
MonitorCommand.lastError = e;
|
||||
MonitorManager.log(prefix + "§6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令时发生异常!");
|
||||
MonitorManager.print(e);
|
||||
MonitorManager.printThrowable(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import org.bukkit.plugin.RegisteredListener;
|
||||
import org.bukkit.plugin.TimedRegisteredListener;
|
||||
|
||||
import cn.citycraft.PluginHelper.ext.kit.Reflect;
|
||||
import cn.citycraft.PluginHelper.kit.PluginKit;
|
||||
import pw.yumc.Yum.commands.MonitorCommand;
|
||||
import pw.yumc.Yum.managers.ConfigManager;
|
||||
import pw.yumc.Yum.managers.MonitorManager;
|
||||
@ -65,7 +64,7 @@ public class ListenerInjector implements EventExecutor {
|
||||
Reflect.on(listener).set("executor", listenerInjector);
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
PluginKit.sc(String.format(inject_error, plugin.getName(), listener.getClass().getName()));
|
||||
MonitorManager.log(String.format(inject_error, plugin.getName(), listener.getClass().getName()));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -118,7 +117,7 @@ public class ListenerInjector implements EventExecutor {
|
||||
}
|
||||
MonitorCommand.lastError = e;
|
||||
MonitorManager.log(prefix + "§6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件时发生异常!");
|
||||
MonitorManager.print(e);
|
||||
MonitorManager.printThrowable(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import cn.citycraft.PluginHelper.ext.kit.Reflect;
|
||||
import cn.citycraft.PluginHelper.kit.PluginKit;
|
||||
import cn.citycraft.PluginHelper.kit.StrKit;
|
||||
import pw.yumc.Yum.commands.MonitorCommand;
|
||||
import pw.yumc.Yum.managers.MonitorManager;
|
||||
@ -52,7 +51,7 @@ public class TaskInjector implements Runnable {
|
||||
}
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
PluginKit.sc(String.format(inject_error, plugin.getName()));
|
||||
MonitorManager.log(String.format(inject_error, plugin.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +97,7 @@ public class TaskInjector implements Runnable {
|
||||
}
|
||||
MonitorCommand.lastError = e;
|
||||
MonitorManager.log(prefix + "§6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务时发生异常!");
|
||||
MonitorManager.print(e);
|
||||
MonitorManager.printThrowable(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,6 +68,10 @@ public class ConfigManager {
|
||||
return network.getBoolean("AllowPrimaryThread", false);
|
||||
}
|
||||
|
||||
public boolean isLogToFile() {
|
||||
return monitor.getBoolean("LogToFile");
|
||||
}
|
||||
|
||||
public boolean isMainThreadCheck() {
|
||||
return thread.getBoolean("MainThreadCheck", true);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ public class MonitorManager {
|
||||
public static String prefix = "§6[§bYum §a能耗监控§6] ";
|
||||
public static int lagTime = 20;
|
||||
public static boolean debug = ConfigManager.i().isMonitorDebug();
|
||||
public static boolean log_to_file = ConfigManager.i().isLogToFile();
|
||||
|
||||
private static Map<String, Long> monitor = new HashMap<>();
|
||||
private static Map<String, Long> task = new HashMap<>();
|
||||
@ -54,21 +55,25 @@ public class MonitorManager {
|
||||
}
|
||||
|
||||
public static void lagTip(final String message) {
|
||||
LogKit.DEFAULT.logSender(prefix + message);
|
||||
log(prefix + message);
|
||||
}
|
||||
|
||||
public static void log(final String message) {
|
||||
LogKit.DEFAULT.logSender(message);
|
||||
if (log_to_file) {
|
||||
LogKit.DEFAULT.logSender(message);
|
||||
} else {
|
||||
PluginKit.sc(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(final Throwable e) {
|
||||
LogKit.DEFAULT.logSender("§6异常名称: §c" + e.getClass().getName());
|
||||
LogKit.DEFAULT.logSender("§6异常说明: §3" + e.getMessage());
|
||||
LogKit.DEFAULT.logSender("§6简易错误信息如下:");
|
||||
public static void printThrowable(final Throwable e) {
|
||||
log("§6异常名称: §c" + e.getClass().getName());
|
||||
log("§6异常说明: §3" + e.getMessage());
|
||||
log("§6简易错误信息如下:");
|
||||
final int l = e.getStackTrace().length > 5 ? 5 : e.getStackTrace().length;
|
||||
for (int i = 0; i < l; i++) {
|
||||
final StackTraceElement ste = e.getStackTrace()[i];
|
||||
LogKit.DEFAULT.logSender(" §e位于 §c" + ste.getClassName() + "." + ste.getMethodName() + "(§4" + ste.getFileName() + ":" + ste.getLineNumber() + "§c)");
|
||||
log(" §e位于 §c" + ste.getClassName() + "." + ste.getMethodName() + "(§4" + ste.getFileName() + ":" + ste.getLineNumber() + "§c)");
|
||||
}
|
||||
if (debug) {
|
||||
PluginKit.sc("§c开发人员调试信息如下:");
|
||||
|
@ -3,12 +3,14 @@
|
||||
############################
|
||||
|
||||
#配置版本号 请勿修改!!!
|
||||
Version: 1.2
|
||||
Version: 1.3
|
||||
|
||||
#是否开启
|
||||
Enable: true
|
||||
#是否显示开发人员信息
|
||||
Debug: false
|
||||
#是否保存Lag日志到文件
|
||||
LogToFile: true
|
||||
#忽略检测列表
|
||||
Ignore:
|
||||
- PluginHelper
|
Loading…
Reference in New Issue
Block a user