Skip to content

Commit

Permalink
[feat]: update v1.5.5
Browse files Browse the repository at this point in the history
* [build]: updated dependencies

* [fix]: crash when no log file is available

* [fix]: double-click navigation crash (#98)

* [refactor]: rewritten recording feature to add custom recorders

* [fix]: memory problems

* [fix]: zip recording export

* [refactor]: small code improvements

* [feat]: saving all recorded logs

* [feat]: exporting selected logs

* [fix]: fixed text for LogsFragment

* [build]: bumped app version

* [feat]: update zh_rCN translation

---------

Co-authored-by: huajijam <29218242+huajijam@users.noreply.github.com>
  • Loading branch information
F0x1d and huajijam authored Feb 5, 2024
1 parent 0df9e89 commit 7eec655
Show file tree
Hide file tree
Showing 35 changed files with 416 additions and 237 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.f0x1d.logfox"
minSdk 24
targetSdk 34
versionCode 56
versionName "1.5.4"
versionCode 57
versionName "1.5.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.f0x1d.logfox.extensions

import com.f0x1d.logfox.LogFoxApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

fun onAppScope(block: suspend CoroutineScope.() -> Unit) = LogFoxApp.applicationScope.launch(
Dispatchers.IO
) {
block(this)
}

fun runOnAppScope(block: suspend CoroutineScope.() -> Unit) {
onAppScope(block)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import java.util.LinkedList

fun Uri?.readFileContentsAsFlow(context: Context) = flow {
val uri = this@readFileContentsAsFlow
Expand All @@ -22,7 +23,7 @@ fun Uri?.readFileContentsAsFlow(context: Context) = flow {
context.contentResolver.openInputStream(uri)?.use {
it.bufferedReader().useLines { lines ->
var id = -1L
val logLines = mutableListOf<LogLine>()
val logLines = LinkedList<LogLine>()

for (line in lines) {
val logLine = LogLine(id, line, context) ?: LogLine(
Expand All @@ -33,7 +34,7 @@ fun Uri?.readFileContentsAsFlow(context: Context) = flow {

logLines.add(logLine)
if (logLines.size >= logsDisplayLimit)
break
logLines.removeFirst()

id -= 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ fun LogLine(
context: Context
) = logRegex.find(line.trim())?.run {
val uid = groupValues[2].replace(" ", "")
val integerUid = uidRegex.find(uid)?.run {
val integerUid = uid.toIntOrNull() ?: UIDS.MAPPINGS[uid] ?: uidRegex.find(uid)?.run {
100_000 * groupValues[1].toInt() + 10_000 + groupValues[2].toInt()
} ?: uid.toIntOrNull() ?: UIDS.MAPPINGS[uid]
}

val packageName = uidsCache[uid] ?: integerUid?.let {
context.packageManager.getPackagesForUid(it)?.firstOrNull()?.also { packageName ->
Expand Down Expand Up @@ -48,6 +48,6 @@ fun LogLine(
)
}

private fun mapLevel(level: String) = LogLevel.values().find {
private fun mapLevel(level: String) = LogLevel.entries.find {
it.letter == level
} ?: throw RuntimeException("wtf is $level")
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
package com.f0x1d.logfox.repository.base

import com.f0x1d.logfox.LogFoxApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

abstract class BaseRepository {
protected fun onAppScope(block: suspend CoroutineScope.() -> Unit) = LogFoxApp.applicationScope.launch(Dispatchers.IO) {
block(this)
}

protected fun runOnAppScope(block: suspend CoroutineScope.() -> Unit) {
onAppScope(block)
}
}
abstract class BaseRepository
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.f0x1d.logfox.extensions.logline.filterAndSearch
import com.f0x1d.logfox.extensions.notifications.cancelAllCrashNotifications
import com.f0x1d.logfox.extensions.notifications.cancelCrashNotificationFor
import com.f0x1d.logfox.extensions.notifications.sendErrorNotification
import com.f0x1d.logfox.extensions.runOnAppScope
import com.f0x1d.logfox.model.LogLine
import com.f0x1d.logfox.repository.logging.base.LoggingHelperItemsRepository
import com.f0x1d.logfox.repository.logging.readers.crashes.ANRDetector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.f0x1d.logfox.repository.logging

import com.f0x1d.logfox.database.AppDatabase
import com.f0x1d.logfox.database.entity.UserFilter
import com.f0x1d.logfox.extensions.runOnAppScope
import com.f0x1d.logfox.model.LogLevel
import com.f0x1d.logfox.repository.logging.base.LoggingHelperItemsRepository
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import android.content.SharedPreferences
import com.f0x1d.logfox.R
import com.f0x1d.logfox.extensions.context.toast
import com.f0x1d.logfox.extensions.logline.LogLine
import com.f0x1d.logfox.extensions.updateList
import com.f0x1d.logfox.extensions.onAppScope
import com.f0x1d.logfox.extensions.runOnAppScope
import com.f0x1d.logfox.model.LogLine
import com.f0x1d.logfox.repository.base.BaseRepository
import com.f0x1d.logfox.repository.logging.base.LoggingHelperRepository
Expand All @@ -26,6 +27,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import java.util.LinkedList
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -45,6 +47,8 @@ class LoggingRepository @Inject constructor(
val logsFlow = MutableStateFlow(emptyList<LogLine>())
val serviceRunningFlow = MutableStateFlow(false)

private val logs = LinkedList<LogLine>()
private val logsMutex = Mutex()
private var loggingJob: Job? = null

private var loggingTerminal = terminals.first()
Expand All @@ -63,7 +67,9 @@ class LoggingRepository @Inject constructor(

loggingJob = onAppScope {
helpers.map {
async(Dispatchers.IO) { it.setup() }
async(Dispatchers.IO) {
it.setup()
}
}.awaitAll()

while (isActive) {
Expand Down Expand Up @@ -99,7 +105,9 @@ class LoggingRepository @Inject constructor(

onAppScope {
val closingHelpers = helpers.map {
async(Dispatchers.IO) { it.stop() }
async(Dispatchers.IO) {
it.stop()
}
}

loggingTerminal.exit()
Expand All @@ -108,6 +116,10 @@ class LoggingRepository @Inject constructor(
}

fun clearLogs() = runOnAppScope {
logsMutex.withLock {
logs.clear()
}

logsFlow.update {
emptyList()
}
Expand Down Expand Up @@ -141,21 +153,13 @@ class LoggingRepository @Inject constructor(
return@coroutineScope
}

val updateLines = mutableListOf<LogLine>()
val mutex = Mutex()

val updater = launch(Dispatchers.IO) {
while (isActive) {
delay(loggingInterval)

logsFlow.updateList {
mutex.withLock {
addAll(updateLines)
updateLines.clear()
}

while (size > logsDisplayLimit) {
removeFirst()
logsFlow.update {
logsMutex.withLock {
logs.toList()
}
}
}
Expand All @@ -175,8 +179,11 @@ class LoggingRepository @Inject constructor(
continue
}

mutex.withLock {
updateLines.add(logLine)
logsMutex.withLock {
logs.add(logLine)

while (logs.size > logsDisplayLimit)
logs.removeFirst()
}

helpers.forEach { helper ->
Expand Down
Loading

0 comments on commit 7eec655

Please sign in to comment.