Skip to content

Commit

Permalink
increase size of log buffer and fix bug when adding logs when buffer …
Browse files Browse the repository at this point in the history
…is full
  • Loading branch information
Arian04 committed Aug 23, 2024
1 parent 05967ac commit 86feaac
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ data class LogEntry(
val priority: String,
val tag: String,
val message: String,
val t: Throwable? = null
val throwableString: String? = null,
) {
override fun toString(): String {
return if (t != null) {
"${tag}\t\t${priority}\t\t${message}\t\t${t}"
return if (throwableString != null) {
"${tag}\t\t${priority}\t\t${message}\t\t${throwableString}"
} else {
"${tag}\t\t${priority}\t\t${message}"
}
Expand All @@ -40,15 +40,15 @@ enum class Level(val priority: Int) {
sealed class LogBuffer {
companion object {
// NOTE: adjust limit if this uses too much memory
private const val LIMIT = 1000
private const val LIMIT = 50000
private val buffer = ArrayDeque<LogEntry>(LIMIT)

fun log(priority: Int, tag: String?, message: String, t: Throwable? = null) {
val entry = LogEntry(
priority = priorityToLevel(priority),
tag = tag ?: "unknown_tag",
message = message,
t = t
throwableString = t?.toString()
)

add(entry)
Expand All @@ -57,9 +57,9 @@ sealed class LogBuffer {
private fun add(entry: LogEntry) {
if (buffer.size >= LIMIT) {
buffer.removeFirst()
} else {
buffer.add(entry)
}

buffer.add(entry)
}

private fun priorityToLevel(priority: Int): String {
Expand Down

0 comments on commit 86feaac

Please sign in to comment.