|
|
@@ -0,0 +1,81 @@ |
|
|
|
package cn.org.bjca.trust.push.common |
|
|
|
|
|
|
|
import android.util.Log |
|
|
|
|
|
|
|
class LogHelper { |
|
|
|
companion object { |
|
|
|
const val TAG = "=====>SZYX_PUSH<=====" |
|
|
|
var showLog = true |
|
|
|
|
|
|
|
/** |
|
|
|
* e |
|
|
|
*/ |
|
|
|
fun e(message: String) { |
|
|
|
e(message, null, null) |
|
|
|
} |
|
|
|
|
|
|
|
fun e(message: String, tag: String) { |
|
|
|
e(message, null, tag) |
|
|
|
} |
|
|
|
|
|
|
|
fun e(message: String, tr: Throwable) { |
|
|
|
e(message, tr, null) |
|
|
|
} |
|
|
|
|
|
|
|
fun e(message: String, tr: Throwable?, tag: String?) { |
|
|
|
println(tr, tag) { |
|
|
|
if (tr != null) { |
|
|
|
Log.e(TAG, message, tr) |
|
|
|
} else { |
|
|
|
Log.e(TAG, message) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* d |
|
|
|
*/ |
|
|
|
fun d(message: String, tag: String? = null) { |
|
|
|
d(message, null, tag) |
|
|
|
} |
|
|
|
|
|
|
|
fun d(message: String, tr: Throwable?, tag: String? = null) { |
|
|
|
println(tr, tag) { |
|
|
|
if (tr != null) { |
|
|
|
Log.d(TAG, message, tr) |
|
|
|
} else { |
|
|
|
Log.e(TAG, message) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private fun println(tr: Throwable?, tag: String?, log: () -> Unit) { |
|
|
|
if (!showLog) return |
|
|
|
Log.e( |
|
|
|
TAG, "" |
|
|
|
) |
|
|
|
Log.e( |
|
|
|
TAG, "======================================================================" |
|
|
|
) |
|
|
|
Log.e( |
|
|
|
TAG, getTag(tr, tag) |
|
|
|
) |
|
|
|
Log.e( |
|
|
|
TAG, "----------------${tag ?: "-"}----------------" |
|
|
|
) |
|
|
|
log() |
|
|
|
Log.e( |
|
|
|
TAG, "======================================================================" |
|
|
|
) |
|
|
|
Log.e( |
|
|
|
TAG, "" |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
fun getTag(tr: Throwable?, tag: String?): String { |
|
|
|
val caller: StackTraceElement = |
|
|
|
Thread.currentThread().stackTrace[if (tr != null && tag != null) 5 else 6] |
|
|
|
return "${caller.methodName}(${caller.fileName}:${caller.lineNumber})" |
|
|
|
} |
|
|
|
} |
|
|
|
} |