Skip to content

Commit

Permalink
Fix exclusions bug when multiple log priorities are involved
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanparajuli committed Mar 13, 2021
1 parent f6738e6 commit 4fe384d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -752,14 +752,21 @@ class LogcatLiveFragment : BaseFragment(), ServiceConnection, LogsReceivedListen
private class LogFilter(filterInfo: FilterInfo) : Filter {
private val type = filterInfo.type
private val content = filterInfo.content
private val priorities: Set<String> = if (type == FilterType.LOG_LEVELS) {
filterInfo.content.split(",").toSet()
} else {
emptySet()
}

override fun apply(log: Log): Boolean {
if (content.isEmpty()) {
return true
}

return when (type) {
FilterType.LOG_LEVELS -> log.priority == content
FilterType.LOG_LEVELS -> {
log.priority in priorities
}
FilterType.KEYWORD -> log.msg.containsIgnoreCase(content)
FilterType.TAG -> log.tag.containsIgnoreCase(content)
FilterType.PID -> log.pid.containsIgnoreCase(content)
Expand Down
4 changes: 3 additions & 1 deletion logcat/src/main/java/com/dp/logcat/Logcat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ class Logcat(initialCapacity: Int = INITIAL_LOG_CAPACITY) : Closeable {
logs.add(pendingLogs)

val filteredLogs = pendingLogs.filter { e ->
!exclusions.values.any { it.apply(e) } && filters.values.all { it.apply(e) }
!exclusions.values.any { it.apply(e) }
}.filter { e ->
filters.values.all { it.apply(e) }
}

if (filteredLogs.isNotEmpty()) {
Expand Down

0 comments on commit 4fe384d

Please sign in to comment.