Shorten log recording entries

This commit is contained in:
Philipp Heckel 2022-01-20 21:23:24 -05:00
parent 6efc30b17d
commit 955f3922d1
6 changed files with 17 additions and 7 deletions

View file

@ -70,7 +70,7 @@ dependencies {
// WorkManager
implementation "androidx.work:work-runtime-ktx:2.6.0"
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.preference:preference-ktx:1.1.1'
// Room (SQLite)
def roomVersion = "2.3.0"
@ -81,7 +81,7 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
// Firebase, sigh ... (only Google Play)
playImplementation 'com.google.firebase:firebase-messaging:22.0.0'
playImplementation 'com.google.firebase:firebase-messaging:23.0.0'
// RecyclerView
implementation "androidx.recyclerview:recyclerview:$rootProject.recyclerViewVersion"

View file

@ -288,7 +288,7 @@ interface LogDao {
@Insert
suspend fun insert(entry: LogEntry)
@Query("DELETE FROM log WHERE id NOT IN (SELECT id FROM log ORDER BY id DESC LIMIT :keepCount)")
@Query("DELETE FROM log WHERE id NOT IN (SELECT id FROM log ORDER BY timestamp DESC, id DESC LIMIT :keepCount)")
suspend fun prune(keepCount: Int)
@Query("SELECT * FROM log ORDER BY timestamp ASC, id ASC")

View file

@ -40,7 +40,7 @@ class Log(private val logsDao: LogDao) {
private fun prependDeviceInfo(s: String): String {
return """
This is a log of the ntfy Android app. The log shows up to 5,000 lines.
This is a log of the ntfy Android app. The log shows up to 2,000 lines.
Server URLs (aside from ntfy.sh) and topics have been replaced with fruits 🍌🥝🍋🥥🥑🍊🍎🍑.
Device info:
@ -94,7 +94,7 @@ class Log(private val logsDao: LogDao) {
android.util.Log.ERROR -> "E"
else -> "?"
}
val tag = e.tag.format("%-23s")
val tag = e.tag.format("%23s")
val prefix = "${e.timestamp} $date $level $tag"
val message = if (e.exception != null) {
"${e.message}\nException:\n${e.exception}"
@ -116,7 +116,7 @@ class Log(private val logsDao: LogDao) {
companion object {
private const val TAG = "NtfyLog"
private const val PRUNE_EVERY = 100
private const val ENTRIES_MAX = 5000
private const val ENTRIES_MAX = 2000
private val IGNORE_TERMS = listOf("ntfy.sh")
private val REPLACE_TERMS = listOf(
"banana", "kiwi", "lemon", "coconut", "avocado", "orange", "apple", "peach"

View file

@ -398,6 +398,13 @@ class SettingsActivity : AppCompatActivity() {
lifecycleScope.launch(Dispatchers.IO) {
Log.d(TAG, "Uploading log to $EXPORT_LOGS_UPLOAD_URL ...")
val log = Log.getFormatted()
if (log.length > EXPORT_LOGS_UPLOAD_NOTIFY_SIZE_THRESHOLD) {
requireActivity().runOnUiThread {
Toast
.makeText(context, getString(R.string.settings_advanced_export_logs_uploading), Toast.LENGTH_SHORT)
.show()
}
}
val gson = Gson()
val request = Request.Builder()
.url(EXPORT_LOGS_UPLOAD_URL)
@ -477,5 +484,6 @@ class SettingsActivity : AppCompatActivity() {
private const val EXPORT_LOGS_COPY = "copy"
private const val EXPORT_LOGS_UPLOAD = "upload"
private const val EXPORT_LOGS_UPLOAD_URL = "https://nopaste.net/?f=json" // Run by binwiederhier; see https://github.com/binwiederhier/pcopy
private const val EXPORT_LOGS_UPLOAD_NOTIFY_SIZE_THRESHOLD = 100 * 1024 // Show "Uploading ..." if log larger than X
}
}

View file

@ -250,7 +250,7 @@
<string name="settings_advanced_broadcast_summary_disabled">Apps cannot receive notifications as broadcasts</string>
<string name="settings_advanced_record_logs_key">RecordLogs</string>
<string name="settings_advanced_record_logs_title">Record logs</string>
<string name="settings_advanced_record_logs_summary_enabled">Logs are currently being recorded to your device. Up to 5,000 log lines are stored.</string>
<string name="settings_advanced_record_logs_summary_enabled">Logs are currently being recorded to your device. Up to 2,000 log lines are stored.</string>
<string name="settings_advanced_record_logs_summary_disabled">Enable log recording, so you can share the logs later. This is useful for diagnosing issues.</string>
<string name="settings_advanced_export_logs_key">ExportLogs</string>
<string name="settings_advanced_export_logs_title">Copy/upload logs</string>
@ -258,6 +258,7 @@
<string name="settings_advanced_export_logs_entry_copy">Copy to clipboard</string>
<string name="settings_advanced_export_logs_entry_upload">Upload to nopaste.net</string>
<string name="settings_advanced_export_logs_copied_logs">Logs copied to clipboard</string>
<string name="settings_advanced_export_logs_uploading">Uploading log …</string>
<string name="settings_advanced_export_logs_copied_url">URL copied to clipboard</string>
<string name="settings_advanced_export_logs_error_uploading">Error uploading logs: %1$s</string>
<string name="settings_advanced_clear_logs_key">ClearLogs</string>

View file

@ -2,6 +2,7 @@ package io.heckel.ntfy.util
import android.app.Activity
import com.google.android.play.core.review.ReviewManagerFactory
import io.heckel.ntfy.log.Log
// Open the in-app rate dialog, see https://developer.android.com/guide/playcore/in-app-review/kotlin-java
fun rateApp(activity: Activity) {