add logtube support

This commit is contained in:
Looly
2021-05-26 14:08:48 +08:00
parent e18555fd47
commit 1eff0fa846
12 changed files with 291 additions and 7 deletions

View File

@@ -150,7 +150,25 @@ public class ExceptionUtil {
* @since 4.1.4
*/
public static StackTraceElement getStackElement(int i) {
return getStackElements()[i];
return Thread.currentThread().getStackTrace()[i];
}
/**
* 获取指定层的堆栈信息
*
* @param fqcn 指定类名为基础
* @param i 指定类名的类堆栈相对层数
* @return 指定层的堆栈信息
* @since 5.6.6
*/
public static StackTraceElement getStackElement(String fqcn, int i) {
final StackTraceElement[] stackTraceArray = Thread.currentThread().getStackTrace();
final int index = ArrayUtil.matchIndex((ele) -> StrUtil.equals(fqcn, ele.getClassName()), stackTraceArray);
if(index > 0){
return stackTraceArray[index + i];
}
return null;
}
/**
@@ -160,8 +178,8 @@ public class ExceptionUtil {
* @since 4.1.4
*/
public static StackTraceElement getRootStackElement() {
final StackTraceElement[] stackElements = getStackElements();
return stackElements[stackElements.length - 1];
final StackTraceElement[] stackElements = Thread.currentThread().getStackTrace();
return Thread.currentThread().getStackTrace()[stackElements.length - 1];
}
/**

View File

@@ -1422,8 +1422,8 @@ public class FileUtil extends PathUtil {
pathToUse = StrUtil.removePrefixIgnoreCase(pathToUse, URLUtil.FILE_URL_PREFIX);
// 识别home目录形式并转换为绝对路径
if (pathToUse.startsWith("~")) {
pathToUse = pathToUse.replaceFirst("~", getUserHomePath());
if (StrUtil.startWith(pathToUse, '~')) {
pathToUse = getUserHomePath() + pathToUse.substring(1);
}
// 统一使用斜杠

View File

@@ -26,6 +26,10 @@ public class ExceptionUtilTest {
Assert.assertEquals("main", ele.getMethodName());
}
@Test
public void getStackElementTest(){
}
@Test
public void convertTest() {
// RuntimeException e = new RuntimeException();

View File

@@ -168,6 +168,13 @@ public class FileUtilTest {
Assert.assertEquals(home + "/bar/", FileUtil.normalize("~/foo/../bar/"));
}
@Test
public void normalizeHomePathTest2() {
String home = FileUtil.getUserHomePath().replace('\\', '/');
// 多个~应该只替换开头的
Assert.assertEquals(home + "/~bar/", FileUtil.normalize("~/foo/../~bar/"));
}
@Test
public void normalizeClassPathTest() {
Assert.assertEquals("", FileUtil.normalize("classpath:"));