All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.huanminabc.utils_common.obj.reflect.StackTraceUtil Maven / Gradle / Ivy

There is a newer version: 1.0.5-RELEASE
Show newest version
package com.gitee.huanminabc.utils_common.obj.reflect;

import java.util.Arrays;
import java.util.Optional;

public class StackTraceUtil {
    //获取调用此方法的 类名 方法名,行号
    public static StackTraceElement currentStackTrace() {
        Optional first = Arrays.stream(Thread.currentThread().getStackTrace()).skip(2).findFirst();
        return first.get();
    }
    //类名.方法名(类名.java:行号)
    public static String currentStackTraceString(int num) {
        Optional stackTrace = Arrays.stream(Thread.currentThread().getStackTrace()).skip(num).findFirst();
        StackTraceElement stackTraceElement = stackTrace.get();
        return stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName() + "(" + stackTraceElement.getFileName() + ":" + stackTraceElement.getLineNumber() + ")";
    }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy