/**
* 定位打印的方法
* @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
}
版权声明:本文为wkaia原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。