@@ -49,7 +49,7 @@ class PureeLogger private constructor(
49
49
private val logStore : PureeLogStore ,
50
50
private val dispatcher : CoroutineDispatcher ,
51
51
private val clock : Clock ,
52
- private val registeredLogs : Map <Class <out Any >, Configuration >,
52
+ private val registeredLogs : Map <Class <out PureeLog >, Configuration >,
53
53
private val bufferedOutputs : List <PureeBufferedOutput >
54
54
) {
55
55
private val scope: CoroutineScope = CoroutineScope (dispatcher + CoroutineExceptionHandler { _, throwable ->
@@ -103,6 +103,17 @@ class PureeLogger private constructor(
103
103
}
104
104
}
105
105
106
+ /* *
107
+ * Force-flush all of the buffered logs regardless of the flush interval
108
+ */
109
+ fun flush () {
110
+ scope.launch {
111
+ bufferedOutputs.forEach {
112
+ it.flush()
113
+ }
114
+ }
115
+ }
116
+
106
117
/* *
107
118
* Suspends the background process that periodically emits buffered logs if a [PureeBufferedOutput] is registered
108
119
* through [Builder]. This is called when the [Lifecycle]'s state changes to [Lifecycle.Event.ON_STOP]
@@ -188,7 +199,7 @@ class PureeLogger private constructor(
188
199
@VisibleForTesting
189
200
internal var clock: Clock = Clock .systemUTC()
190
201
191
- private val configuredLogs: MutableMap <Class <out Any >, Configuration > = mutableMapOf ()
202
+ private val configuredLogs: MutableMap <Class <out PureeLog >, Configuration > = mutableMapOf ()
192
203
private val outputIds: MutableSet <String > = mutableSetOf ()
193
204
private val bufferedOutputs: MutableList <PureeBufferedOutput > = mutableListOf ()
194
205
@@ -199,7 +210,7 @@ class PureeLogger private constructor(
199
210
* @param logTypes The log types of the objects on which the [PureeFilter] will be applied. If a type is included more
200
211
* than once, the [PureeFilter] will be applied multiple times.
201
212
*/
202
- fun filter (filter : PureeFilter , vararg logTypes : Class <out Any >): Builder {
213
+ fun filter (filter : PureeFilter , vararg logTypes : Class <out PureeLog >): Builder {
203
214
logTypes.forEach {
204
215
configuredLogs.getOrPut(it, { Configuration () }).filters.add(filter)
205
216
}
@@ -214,10 +225,7 @@ class PureeLogger private constructor(
214
225
* [PureeOutput] should be registered and duplicates are ignored.
215
226
* @param logTypes The log types of the objects that will be sent to the [PureeOutput].
216
227
*/
217
- fun output (
218
- output : PureeOutput ,
219
- vararg logTypes : Class <out Any >
220
- ): Builder {
228
+ fun output (output : PureeOutput ,vararg logTypes : Class <out PureeLog >): Builder {
221
229
if (output is PureeBufferedOutput ) {
222
230
if (output.uniqueId in outputIds) {
223
231
throw IllegalArgumentException (" Cannot register another PureeBufferedOutput with uniqueId: ${output.uniqueId} ." )
0 commit comments