|
|
|
@ -4,7 +4,8 @@ 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;
|
|
|
|
|
import cn.hutool.log.level.Level;
|
|
|
|
|
import xyz.wbsite.jmacro.ex.MacroErrorException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 日志记录器
|
|
|
|
@ -15,9 +16,10 @@ import xyz.wbsite.jmacro.JMainService;
|
|
|
|
|
*/
|
|
|
|
|
public class Logger {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void info(String format, Object... arg) {
|
|
|
|
|
DateTime date = DateUtil.date();
|
|
|
|
|
String level = "INFO";
|
|
|
|
|
String level = Level.INFO.toString();
|
|
|
|
|
String log = StrUtil.format(format, arg);
|
|
|
|
|
String name = CallerUtil.getCallerCaller().getSimpleName();
|
|
|
|
|
// 获取当前线程的堆栈追踪
|
|
|
|
@ -27,17 +29,16 @@ public class Logger {
|
|
|
|
|
System.out.println(StrUtil.format("[{}] [{}] {} [{}:{}]", date, level, log, name, lineNumber));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void error(String log, Object... arg) {
|
|
|
|
|
info(log, arg);
|
|
|
|
|
// 中断1分钟
|
|
|
|
|
for (int i = 0; i < 60; i++) {
|
|
|
|
|
if (JMainService.getInstance().run) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static void error(String format, Object... arg) {
|
|
|
|
|
DateTime date = DateUtil.date();
|
|
|
|
|
String level = Level.ERROR.toString();
|
|
|
|
|
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));
|
|
|
|
|
throw new MacroErrorException(StrUtil.format(format, arg));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|