/**
* 定位打印的方法
* @return
*/
private fun logLocation(index: Int): StringBuilder? {
val logStackTrace = getLogStackTrace(index)
if (logStackTrace != null) {
val stringBuilder = StringBuilder()
stringBuilder.append(jumpKeyWord).append(" (").append(logStackTrace.fileName).append(":").append("${logStackTrace.lineNumber})")
return stringBuilder
} else return null
}
/**
* 获取调用打印方法的栈 index 调用打印i/e/json的index为0
* @return
*/
private fun getLogStackTrace(index: Int): StackTraceElement? {
var logTackTraces: StackTraceElement? = null
val stackTraces = Thread.currentThread().stackTrace
var i = 0
while (i < stackTraces.size) {
val stackTrace = stackTraces[i]
if (stackTrace.className == LogUtil::class.java.name) {
logTackTraces = stackTraces[i + 3 + index]
i = stackTraces.size
}
i++
}
return logTackTraces
}
获取log在位置
最新推荐文章于 2021-04-07 12:48:22 发布