SimpleEventLogger

class SimpleEventLogger(storage: Storage, partitionId: String = "default", expireAfter: Duration = 60.days, clock: Clock = Clock.System, onAddEvent: suspend (event: Event) -> Map<String, DataItem>? = { _ -> emptyMap() }, scope: CoroutineScope = CoroutineScope(Dispatchers.Default)) : EventLogger

An implementation of EventLogger backed by a Storage implementation.

This implementation also provides an observable flow (eventFlow) that emits whenever the underlying event data is modified, making it easy for UI or other observers to react to changes.

Applications may use onAddEvent to determine if an event should be dropped or if additional application-specific data should be amended to the event. For example an application may have per-document setting on whether to log events or it may add a GPS-location for proximity presentment events.

Constructors

Link copied to clipboard
constructor(storage: Storage, partitionId: String = "default", expireAfter: Duration = 60.days, clock: Clock = Clock.System, onAddEvent: suspend (event: Event) -> Map<String, DataItem>? = { _ -> emptyMap() }, scope: CoroutineScope = CoroutineScope(Dispatchers.Default))

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val eventFlow: SharedFlow<Unit>

A SharedFlow that emits a Unit whenever an event is added, deleted, or when all events are cleared. Observers can collect this flow to know when to refresh their data.

Functions

Link copied to clipboard
open suspend override fun addEvent(event: Event): Event?

Adds a new event to the logger.

Link copied to clipboard
open override fun addEventAsync(event: Event)

Asynchronously adds an event to the event log.

Link copied to clipboard
suspend fun deleteAllEvents()

Deletes all events within the current partition.

Link copied to clipboard
suspend fun deleteEvent(event: Event): Boolean

Deletes a specific event from the logger.

Link copied to clipboard
suspend fun getEvents(limit: Int = Int.MAX_VALUE, afterEventId: String? = null): List<Event>

Retrieves all events stored in the current partition.