public static void main(String[] args) {
System.out.println(getTraceInfo("打印一下日志"));
System.out.println(getTraceInfo("再来一条"));
}
public static String getTraceInfo(String msg,Object... var2) {
StringBuffer sb = new StringBuffer();
StackTraceElement[] stacks = new Throwable().getStackTrace();
sb.append(MessageFormatter.format("{} [{}] INFO {}:{} - ",
DateUtil.date(),Thread.currentThread().getName(),stacks[1].getClassName(),stacks[1].getLineNumber()));
return sb.append(MessageFormatter.format(msg,var2)).toString();
}
java 获取当前程序行数、方法名(模拟log输出)
最新推荐文章于 2023-12-22 19:05:05 发布