Skip to content

Commit

Permalink
Add error log reporting(4)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhwdev committed Oct 11, 2021
1 parent dcceec4 commit 33aefd7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
14 changes: 10 additions & 4 deletions app/src/main/java/com/lhwdev/selfTestMacro/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,12 @@ class MainActivity : AppCompatActivity() {
else -> error("unknown index")
}

shareErrorLog(file)
AlertDialog.Builder(this@MainActivity).apply {
setTitle("개인정보 안내")
setMessage("이 로그를 공유하면 로그 안에 포함된 개인정보를 로그를 공유하는 대상에게 공개하는 것을 동의하게 됩니다.")
setPositiveButton("") { _, _ -> shareErrorLog(file) }
setNegativeButton("취소", null)
}.show()
}
setNegativeButton("취소", null)
}.show()
Expand All @@ -312,9 +317,10 @@ class MainActivity : AppCompatActivity() {
setMessage(
HtmlCompat.fromHtml(
"""
|이현우 개발
|<a href='https://github.com/lhwdev/covid-selftest-macro'>자가진단 앱 웹사이트</a>
|버그 제보 방법: 개발자 모드 (밑의 버튼) > 체크 박스 누르기 > 버그가 생길 때까지 기다리기
|이현우 개발<br>
|<a href='https://github.com/lhwdev/covid-selftest-macro'>자가진단 앱 웹사이트</a><br><br>
|버그 제보 방법: 개발자 모드 (밑의 버튼) > 체크 박스 누르기 > 버그가 생길 때까지 기다리기 > ...에서 '로그 공유하기'
|(안뜨면 앱 나갔다 들어오기) > 공유하면 됨
""".trimMargin(),
0
)
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/java/com/lhwdev/selfTestMacro/debugUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@ internal const val sSelfLog = "log/self_log.txt"
internal const val sErrorLog = "log/error_log.txt"


fun Context.shareErrorLog(file: String) {
private fun File.beforeWrite(): File {
val p = parentFile ?: return this
if(!p.exists()) p.mkdirs()
return this
}

fun Context.shareErrorLog(path: String) {
val file = File(getExternalFilesDir(null)!!, path)
if(!file.exists()) {
showToast("로그 파일이 존재하지 않습니다.")
return
}
val uri = FileProvider.getUriForFile(
this,
"com.lhwdev.selfTestMacro.file_provider",
File(getExternalFilesDir(null)!!, file)
file
)

val intent = Intent().apply {
Expand All @@ -46,7 +57,7 @@ fun Context.selfLog(description: String, error: Throwable? = null, force: Boolea
if(!force && !isDebugEnabled) return

val log = logOutput ?: run {
val log = File(getExternalFilesDir(null)!!, sSelfLog)
val log = File(getExternalFilesDir(null)!!, sSelfLog).beforeWrite()
logOutput = log
log
}
Expand Down Expand Up @@ -92,7 +103,7 @@ suspend fun Context.onError(error: Throwable, description: String = "???", force
suspend fun Context.writeErrorLog(info: String) {
try {
withContext(Dispatchers.IO) {
File(getExternalFilesDir(null)!!, sErrorLog).appendText(info)
File(getExternalFilesDir(null)!!, sErrorLog).beforeWrite().appendText(info)
}
} catch(e: Throwable) {
// ignore errors
Expand Down

0 comments on commit 33aefd7

Please sign in to comment.