object LogUtils {
fun log(message: String?) {
log(null, message)
}
fun log(tag: String? =null, message: String?) {
var content = message
if (message.isNullOrEmpty()) {
content ="NULL "
}
val trace = Throwable().fillInStackTrace().stackTrace
var caller: String? =""
var callingClass =""
var callFile: String? =""
var lineNumber =0
for (iin 2 until trace.size) {
val clazz: Class<*> = trace[i].javaClass
if (clazz != LogUtils::class.java) {
callingClass = trace[i].className
callingClass = callingClass.substring(
callingClass
.lastIndexOf('.') +1
)
caller = trace[i].methodName
callFile = trace[i].fileName
lineNumber = trace[i].lineNumber
break
}
}
// val method = java.lang.String.format(
// Locale.US,
// "[%03d] %s.%s(%s:%d)",
// Thread.currentThread().id,
// callingClass,
// caller,
// callFile,
// lineNumber
// )
val method ="($callFile,$lineNumber)"
Log.d(tag ?: callFile, content + method)
}
}
LogUtils
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 刚刚的重新排版一下 /** Created by sakura on 2016/9/29./public clas...
- //Clojure入门教程: Clojure – Functional Programming for the J...