Skip to content

Commit 66e23e3

Browse files
author
qwe7002
committed
chore(LogActivity, MainActivity): improve error logging and refine continuation line detection
1 parent 56ff2e2 commit 66e23e3

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

app/src/main/java/com/qwe7002/telegram_sms/LogActivity.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,21 @@ class LogActivity : AppCompatActivity() {
130130
if (line.isNotEmpty() && !line.startsWith("------")) {
131131
val parsed = parseLogLine(entryId, line)
132132

133-
// Check if this is a continuation line (same timestamp, tag, and message starts with whitespace or is a simple exception name)
133+
// Check if this is a continuation line (same timestamp, tag, and message is part of a stack trace)
134+
val msg = parsed.message
134135
val isContinuation = lastEntry != null &&
135136
lastTimestamp == parsed.timestamp &&
136137
lastTag == parsed.tag &&
137-
(parsed.message.startsWith("\t") ||
138-
parsed.message.startsWith(" ") ||
139-
parsed.message.matches(Regex("^\\s+at\\s+.*")) ||
140-
parsed.message.matches(Regex("^\\s*Caused by:.*")) ||
141-
parsed.message.matches(Regex("^\\s*Suppressed:.*")) ||
142-
parsed.message.matches(Regex("^\\s*\\.{3}\\s+\\d+\\s+more\\s*$")) ||
143-
parsed.message.matches(Regex("^[a-zA-Z]+(\\.[a-zA-Z]+)*Exception.*")) ||
144-
parsed.message.matches(Regex("^[a-zA-Z]+(\\.[a-zA-Z]+)*Error.*")) ||
145-
parsed.message.trim().isEmpty() && parsed.message.isNotEmpty())
138+
(msg.startsWith("\t") ||
139+
msg.startsWith(" ") ||
140+
msg.matches(Regex("^\\s*at\\s+.*")) ||
141+
msg.matches(Regex("^\\s*Caused by:.*")) ||
142+
msg.matches(Regex("^\\s*Suppressed:.*")) ||
143+
msg.matches(Regex("^\\s*\\.{3}\\s+\\d+\\s+more\\s*$")) ||
144+
msg.matches(Regex("^[a-zA-Z]+(\\.[a-zA-Z0-9_\$]+)*Exception.*")) ||
145+
msg.matches(Regex("^[a-zA-Z]+(\\.[a-zA-Z0-9_\$]+)*Error.*")) ||
146+
msg.matches(Regex("^[a-zA-Z]+(\\.[a-zA-Z0-9_\$]+)*:\\s+.*")) ||
147+
(msg.trim().isEmpty() && msg.isNotEmpty()))
146148

147149
if (isContinuation) {
148150
// Add to the last entry's continuation lines

app/src/main/java/com/qwe7002/telegram_sms/MainActivity.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class MainActivity : AppCompatActivity() {
258258
val errorHead = "Get chat ID failed: "
259259
call.enqueue(object : Callback {
260260
override fun onFailure(call: Call, e: IOException) {
261-
Log.d(Const.TAG, "onFailure: $e")
261+
Log.e(Const.TAG, "onResponse: ", e)
262262
progressDialog.cancel()
263263
val message = errorHead + e.message
264264
Log.e(Const.TAG, message)
@@ -354,6 +354,7 @@ class MainActivity : AppCompatActivity() {
354354
.show()
355355
}
356356
} catch (e: Exception) {
357+
Log.e(Const.TAG, "onResponse: ", e)
357358
val errorMessage = errorHead + "Failed to parse response: ${e.message}"
358359
Log.e(Const.TAG, errorMessage)
359360
runOnUiThread { showErrorDialog(errorMessage) }
@@ -467,7 +468,7 @@ class MainActivity : AppCompatActivity() {
467468
val errorHead = "Send message failed: "
468469
call.enqueue(object : Callback {
469470
override fun onFailure(call: Call, e: IOException) {
470-
Log.d(Const.TAG, "onFailure: $e")
471+
Log.e(Const.TAG, "onResponse: ", e)
471472
progressDialog.cancel()
472473
val errorMessage = errorHead + e.message
473474
Log.e(Const.TAG, errorMessage)
@@ -491,7 +492,7 @@ class MainActivity : AppCompatActivity() {
491492
showErrorDialog(errorMessage)
492493
}
493494
} catch (e: Exception) {
494-
e.printStackTrace()
495+
Log.e(Const.TAG, "onResponse: ", e)
495496
val errorMessage = errorHead + "Failed to parse error response"
496497
Log.e(Const.TAG, errorMessage)
497498
runOnUiThread { showErrorDialog(errorMessage) }
@@ -500,7 +501,7 @@ class MainActivity : AppCompatActivity() {
500501
}
501502
if (newBotToken != botTokenSave) {
502503
Log.i(
503-
this::class.simpleName,
504+
Const.TAG,
504505
"onResponse: The current bot token does not match the saved bot token, clearing the message database."
505506
)
506507
MMKV.mmkvWithID(MMKVConst.CHAT_ID).clearAll()

0 commit comments

Comments
 (0)