개발/안드로이드
SQLite 쿼리 로그 보기 + Room에서 쿼리 로그 보기
장모
2021. 11. 24. 01:27
에뮬레이터나 루팅된 기기라면 간단히 태그를 VERBOSE로 설정하면 된다.
adb shell setprop log.tag.SQLiteStatements VERBOSE
SQLite의 정보성 로그를 보고려면
adb shell setprop log.tag.SQLiteLog VERBOSE
쿼리의 실행 시간을 보고 싶다면
adb shell setprop log.tag.SQLiteTime VERBOSE
출처
Room을 사용하면 데이터베이스를 생성할 때 QueryCallback에서 로그를 출력할 수 있다. 루팅 필요 없이 실기기에서도 사용할 수 있는 것이 장점.
Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
FILENAME
).setQueryCallback(RoomDatabase.QueryCallback { sqlQuery, bindArgs ->
Log.i("RoomLog", "$sqlQuery $bindArgs")
}, Executors.newSingleThreadExecutor())
.build()