-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish removing stately in favor of atomics
- Loading branch information
1 parent
717d8aa
commit 72534c6
Showing
3 changed files
with
20 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,49 @@ | ||
package com.juul.tuulbox.logging | ||
|
||
import co.touchlab.stately.isolate.IsolateState | ||
import kotlinx.atomicfu.atomic | ||
import kotlinx.atomicfu.getAndUpdate | ||
|
||
class CallListLogger : Logger { | ||
|
||
private val mutableVerboseCalls = IsolateState { mutableListOf<Call>() } | ||
val verboseCalls: List<Call> get() = mutableVerboseCalls.access { ArrayList(it) } | ||
private val atomicVerboseCalls = atomic(emptyList<Call>()) | ||
val verboseCalls: List<Call> get() = atomicVerboseCalls.value | ||
|
||
private val mutableDebugCalls = IsolateState { mutableListOf<Call>() } | ||
val debugCalls: List<Call> get() = mutableDebugCalls.access { ArrayList(it) } | ||
private val atomicDebugCalls = atomic(emptyList<Call>()) | ||
val debugCalls: List<Call> get() = atomicDebugCalls.value | ||
|
||
private val mutableInfoCalls = IsolateState { mutableListOf<Call>() } | ||
val infoCalls: List<Call> get() = mutableInfoCalls.access { ArrayList(it) } | ||
private val atomicInfoCalls = atomic(emptyList<Call>()) | ||
val infoCalls: List<Call> get() = atomicInfoCalls.value | ||
|
||
private val mutableWarnCalls = IsolateState { mutableListOf<Call>() } | ||
val warnCalls: List<Call> get() = mutableWarnCalls.access { ArrayList(it) } | ||
private val atomicWarnCalls = atomic(emptyList<Call>()) | ||
val warnCalls: List<Call> get() = atomicWarnCalls.value | ||
|
||
private val mutableErrorCalls = IsolateState { mutableListOf<Call>() } | ||
val errorCalls: List<Call> get() = mutableErrorCalls.access { ArrayList(it) } | ||
private val atomicErrorCalls = atomic(emptyList<Call>()) | ||
val errorCalls: List<Call> get() = atomicErrorCalls.value | ||
|
||
private val mutableAssertCalls = IsolateState { mutableListOf<Call>() } | ||
val assertCalls: List<Call> get() = mutableAssertCalls.access { ArrayList(it) } | ||
private val atomicAssertCalls = atomic(emptyList<Call>()) | ||
val assertCalls: List<Call> get() = atomicAssertCalls.value | ||
|
||
override fun verbose(tag: String, message: String, throwable: Throwable?) { | ||
mutableVerboseCalls.access { it += Call(tag = tag, message = message, throwable = throwable) } | ||
atomicVerboseCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) } | ||
} | ||
|
||
override fun debug(tag: String, message: String, throwable: Throwable?) { | ||
mutableDebugCalls.access { it += Call(tag = tag, message = message, throwable = throwable) } | ||
atomicDebugCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) } | ||
} | ||
|
||
override fun info(tag: String, message: String, throwable: Throwable?) { | ||
mutableInfoCalls.access { it += Call(tag = tag, message = message, throwable = throwable) } | ||
atomicInfoCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) } | ||
} | ||
|
||
override fun warn(tag: String, message: String, throwable: Throwable?) { | ||
mutableWarnCalls.access { it += Call(tag = tag, message = message, throwable = throwable) } | ||
atomicWarnCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) } | ||
} | ||
|
||
override fun error(tag: String, message: String, throwable: Throwable?) { | ||
mutableErrorCalls.access { it += Call(tag = tag, message = message, throwable = throwable) } | ||
atomicErrorCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) } | ||
} | ||
|
||
override fun assert(tag: String, message: String, throwable: Throwable?) { | ||
mutableAssertCalls.access { it += Call(tag = tag, message = message, throwable = throwable) } | ||
atomicAssertCalls.getAndUpdate { it + Call(tag = tag, message = message, throwable = throwable) } | ||
} | ||
} |