|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package xyz.wbsite.jmacro.util;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.lang.caller.CallerUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import xyz.wbsite.jmacro.JMainService;
|
|
|
|
|
|
|
|
|
@ -13,30 +15,29 @@ import xyz.wbsite.jmacro.JMainService;
|
|
|
|
|
*/
|
|
|
|
|
public class Logger {
|
|
|
|
|
|
|
|
|
|
public static boolean isDebug = false;
|
|
|
|
|
|
|
|
|
|
public static void setDebug(boolean isDebug) {
|
|
|
|
|
Logger.isDebug = isDebug;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void debug(String log, Object... arg) {
|
|
|
|
|
if (isDebug) {
|
|
|
|
|
System.out.println("[DEBUG]" + DateUtil.date() + " " + StrUtil.format(log, arg));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void info(String log, Object... arg) {
|
|
|
|
|
System.out.println("[INFO ]" + DateUtil.date() + " " + StrUtil.format(log, arg));
|
|
|
|
|
public static void info(String format, Object... arg) {
|
|
|
|
|
DateTime date = DateUtil.date();
|
|
|
|
|
String level = "INFO";
|
|
|
|
|
String log = StrUtil.format(format, arg);
|
|
|
|
|
String name = CallerUtil.getCallerCaller().getSimpleName();
|
|
|
|
|
// 获取当前线程的堆栈追踪
|
|
|
|
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
|
|
|
|
// 通常堆栈追踪数组的第三个元素是logMessage方法的调用者
|
|
|
|
|
int lineNumber = stackTrace[2].getLineNumber();
|
|
|
|
|
System.out.println(StrUtil.format("[{}] [{}] {} [{}:{}]", date, level, log, name, lineNumber));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void error(String log, Object... arg) {
|
|
|
|
|
System.out.println("[ERROR]" + DateUtil.date() + " " + StrUtil.format(log, arg));
|
|
|
|
|
while (JMainService.getInstance().run){
|
|
|
|
|
info(log, arg);
|
|
|
|
|
// 中断1分钟
|
|
|
|
|
for (int i = 0; i < 60; i++) {
|
|
|
|
|
if (JMainService.getInstance().run) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(100);
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|