feat: 添加日志记录功能

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-22 20:52:41 +08:00
parent 720c796889
commit 5f3db15b41
5 changed files with 24 additions and 14 deletions

View File

@ -44,16 +44,16 @@ import pw.yumc.Yum.models.RepoSerialization.Repositories;
*/
public class YumCommand implements HandlerCommands, Listener {
private final String prefix = "§6[§bYum §a插件管理§6] ";
private final String not_found_from_bukkit = prefix + "§c未在BukkitDev搜索到 %s 的相关插件!";
private final String not_found_id_from_bukkit = prefix + "§c未在BukkitDev搜索到ID为 %s 的相关插件!";
private final String searchlimit = prefix + "§c为保证搜索速度和准确性 关键词必须大于 3 个字符!";
private final String searching = prefix + "§a正在从BukkitDev获取 §b%s §a的相关数据...";
private final String searching = prefix + "§a正在从 §eBukkitDev 获取 §b%s §a的相关数据...";
private final String not_found_from_bukkit = prefix + "§c未在 §eBukkitDev 搜索到 %s 的相关插件!";
private final String result = prefix + "§6关键词 §b%s §6的搜索结果如下:";
private final String bukkitlistprefix = " §6插件ID §3插件名称 §d发布类型 §a操作";
private final String bukkitlist = "§6- §e%-6s §b%-25s §d%-10s";
private final String fsearching = prefix + "§a正在从BukkitDev获取ID §b%s §a的文件列表...";
private final String fsearching = prefix + "§a正在从 §eBukkitDev 获取ID §b%s §a的文件列表...";
private final String not_found_id_from_bukkit = prefix + "§c未在 §eBukkitDev 搜索到ID为 %s 的相关插件!";
private final String filelistprefix = " §6插件名称 §3游戏版本 §d发布类型 §a操作";
private final String filelist = "§6- §b%-20s §3%-15s §d%-10s";

View File

@ -109,7 +109,7 @@ public class CommandInjector implements TabExecutor {
final long end = System.nanoTime();
final long lag = end - start;
if (Bukkit.isPrimaryThread() && lag / 1000000 > MonitorManager.lagTime) {
PluginKit.sc("§6[§bYum §a能耗监控§6] §c注意! §6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令 §c耗时 §4" + lag / 1000000 + "ms!");
MonitorManager.lagTip("§c注意! §6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令 §c耗时 §4" + lag / 1000000 + "ms!");
}
totalTime += lag;
count++;
@ -124,7 +124,7 @@ public class CommandInjector implements TabExecutor {
sender.sendMessage("§6异常名称: §c" + e.getClass().getName());
sender.sendMessage("§6异常说明: §3" + e.getMessage());
MonitorCommand.lastError = e;
PluginKit.sc(prefix + "§6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令时发生异常!");
MonitorManager.log(prefix + "§6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令时发生异常!");
MonitorManager.print(e);
}
return false;

View File

@ -99,7 +99,7 @@ public class ListenerInjector implements EventExecutor {
final String en = event.getEventName();
final long lag = end - start;
if (lag / 1000000 > MonitorManager.lagTime && !ConfigManager.i().getMonitorIgnoreList().contains(plugin.getName())) {
PluginKit.sc("§6[§bYum §a能耗监控§6] §c注意! §6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件 §c耗时 §4" + lag / 1000000 + "ms!");
MonitorManager.lagTip("§c注意! §6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件 §c耗时 §4" + lag / 1000000 + "ms!");
}
if (eventTotalTime.containsKey(en)) {
eventTotalTime.put(en, eventTotalTime.get(en) + lag);
@ -117,7 +117,7 @@ public class ListenerInjector implements EventExecutor {
e = e.getCause();
}
MonitorCommand.lastError = e;
PluginKit.sc(prefix + "§6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件时发生异常!");
MonitorManager.log(prefix + "§6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件时发生异常!");
MonitorManager.print(e);
}
}

View File

@ -87,7 +87,7 @@ public class TaskInjector implements Runnable {
final long end = System.nanoTime();
final long lag = end - start;
if (Bukkit.isPrimaryThread() && lag / 1000000 > MonitorManager.lagTime) {
PluginKit.sc("§6[§bYum §a能耗监控§6] §c注意! §6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务 §c耗时 §4" + lag / 1000000 + "ms!");
MonitorManager.lagTip("§6[§bYum §a能耗监控§6] §c注意! §6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务 §c耗时 §4" + lag / 1000000 + "ms!");
}
totalTime += lag;
count++;
@ -97,7 +97,7 @@ public class TaskInjector implements Runnable {
e = e.getCause();
}
MonitorCommand.lastError = e;
PluginKit.sc(prefix + "§6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务时发生异常!");
MonitorManager.log(prefix + "§6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务时发生异常!");
MonitorManager.print(e);
}

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import cn.citycraft.PluginHelper.kit.LogKit;
import cn.citycraft.PluginHelper.kit.PluginKit;
/**
@ -18,6 +19,7 @@ import cn.citycraft.PluginHelper.kit.PluginKit;
* @author
*/
public class MonitorManager {
public static String prefix = "§6[§bYum §a能耗监控§6] ";
public static int lagTime = 20;
public static boolean debug = ConfigManager.i().isMonitorDebug();
@ -51,14 +53,22 @@ public class MonitorManager {
return new MonitorInfo(monitor.get(pname) / um, cmd.get(pname) / um, event.get(pname) / um, task.get(pname) / um);
}
public static void lagTip(final String message) {
LogKit.DEFAULT.logSender(prefix + message);
}
public static void log(final String message) {
LogKit.DEFAULT.logSender(message);
}
public static void print(final Throwable e) {
PluginKit.sc("§6异常名称: §c" + e.getClass().getName());
PluginKit.sc("§6异常说明: §3" + e.getMessage());
PluginKit.sc("§6简易错误信息如下:");
LogKit.DEFAULT.logSender("§6异常名称: §c" + e.getClass().getName());
LogKit.DEFAULT.logSender("§6异常说明: §3" + e.getMessage());
LogKit.DEFAULT.logSender("§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];
PluginKit.sc(" §e位于 §c" + ste.getClassName() + "." + ste.getMethodName() + "(§4" + ste.getFileName() + ":" + ste.getLineNumber() + "§c)");
LogKit.DEFAULT.logSender(" §e位于 §c" + ste.getClassName() + "." + ste.getMethodName() + "(§4" + ste.getFileName() + ":" + ste.getLineNumber() + "§c)");
}
if (debug) {
PluginKit.sc("§c开发人员调试信息如下:");