반응형
class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()
DEBUG = isDebuggable(this)
}
/**
* get Debug Mode
*
* @param context
* @return
*/
private fun isDebuggable(context: Context): Boolean {
var debuggable = false
val pm: PackageManager = context.getPackageManager()
try {
val appinfo: ApplicationInfo = pm.getApplicationInfo(context.getPackageName(), 0)
debuggable = 0 != appinfo.flags and ApplicationInfo.FLAG_DEBUGGABLE
} catch (e: PackageManager.NameNotFoundException) {
/* debuggable variable will remain false */
}
return debuggable
}
companion object {
var DEBUG = false
}
}
object Dlog {
val TAG = "KONG"
/** Log Level Error */
fun e(message: String?) {
if (GlobalApplication.DEBUG) buildLogMsg(message)?.let { Log.e(TAG, it) }
}
/** Log Level Warning */
fun w(message: String?) {
if (GlobalApplication.DEBUG) buildLogMsg(message)?.let { Log.w(TAG, it) }
}
/** Log Level Information */
fun i(message: String?) {
if (GlobalApplication.DEBUG) buildLogMsg(message)?.let { Log.i(TAG, it) }
}
/** Log Level Debug */
fun d(message: String?) {
if (GlobalApplication.DEBUG) buildLogMsg(message)?.let { Log.d(TAG, it) }
}
/** Log Level Verbose */
fun v(message: String?) {
if (GlobalApplication.DEBUG) buildLogMsg(message)?.let { Log.v(TAG, it) }
}
fun buildLogMsg(message: String?): String? {
val ste = Thread.currentThread().stackTrace[4]
val sb = StringBuilder()
sb.append("[")
sb.append("${ste.fileName} : ${ste.lineNumber}")
sb.append("::")
sb.append(ste.methodName)
sb.append("]")
sb.append(message)
return sb.toString()
}
}
디버그 모드일때만 로그 보기
반응형
'Android' 카테고리의 다른 글
Android Https body 통신 로그 보기 (0) | 2022.10.27 |
---|---|
블루투스 스캔할때 name, address, rssi 받아오기 (0) | 2022.10.26 |
Android Release 모드에서 Log 보기 (0) | 2022.10.12 |
Android filesDir.path 폴더 안에 하위 목록까지 삭제하기 (0) | 2022.09.27 |
Kotlin for문 (0) | 2022.08.18 |
댓글