InMemoryLogStore class final
In-memory store: the current session's log without a database.
For tests, prototypes and apps that only need a viewer over the current session. Entries do not survive a process restart.
Keeps entries as LogStoreBase passes them (LogEntry.withoutLiveObjects): without live
LogError.original and LogError.report, with the call site already resolved. Otherwise a store of a
thousand entries would hold a thousand original errors and platform reports with everything they
reference. Entries are == to the written ones.
Entries are kept in store order (by time, then by id), so a query page does not need a scan of the whole log (queryInMemory), and tags are counted on write and removal (queryTags does not iterate entries).
The log is capped at limit (default defaultLimit): when exceeded, the oldest entries are removed with LogEntriesRemovedById in changes. Without a limit a long session would grow both memory and the cost of every query without bound.
- Inheritance
-
- Object
- LogStoreBase
- InMemoryLogStore
Constructors
- InMemoryLogStore({int? limit = defaultLimit})
Properties
-
changes
→ Stream<
LogStoreChange> -
Broadcast stream of changes: LogEntriesAdded for each saved batch of
entries, LogEntriesRemoved describing removed entries,
LogStoreInvalidated when a change cannot be described more precisely.
There may be several subscribers (for example, two open viewers).
no setterinherited
-
entries
→ List<
StoredLogEntry> -
Stored entries in store order: by time, entries with equal time in write order.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClosed → bool
-
Whether close has been called: from then on operations throw StateError.
no setterinherited
- limit → int?
-
Maximum number of kept entries;
nullmeans no limit (InMemoryLogStore(limit: null)), for tests where every entry matters.final - name → String
-
Store name in messages (StateError after close). Defaults to the
class name, unreadable in an
--obfuscatebuild; a store should return a constant string, as sinks do (LogSink.name).no setteroverride - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → Future< void> -
Removes all entries (onClear) and sends AllLogEntriesRemoved.
Throws StateError after close.
inherited
-
close(
) → Future< void> -
Releases resources (onClose) and closes changes. A repeated call
closes nothing again and returns the result of the first.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onClear(
) → Future< void> -
Removes all entries. The base sends AllLogEntriesRemoved.
override
-
onClose(
) → Future< void> -
Releases the store's resources. Called once, from close; the base
closes changes afterwards. Does nothing by default.
inherited
-
onQueryEntries(
LogQuery query) → Future< LogPage> -
A page of entries for
query; see LogStore.queryEntries.override -
onQueryTags(
) → Future< Set< String> > -
All tags of stored entries; see LogStore.queryTags.
override
-
onRemoveBefore(
DateTime time) → Future< void> -
Removes entries strictly before
time. The base sends LogEntriesRemovedBefore.override -
onRetainNewest(
int count) → Future< Set< int> ?> -
Keeps the
countnewest entries in store order and returns the removed ids (an empty set if there was nothing to remove) ornullif they cannot be determined cheaply: the base then sends LogStoreInvalidated. In SQL,DELETE … RETURNING idprovides the ids.override -
onWriteEntries(
List< LogEntry> entries) → Future<List< StoredLogEntry> > -
Saves
entriesin this order and returns them with ids (StoredLogEntry.id): increasing in save order and never reused (in SQLite,INTEGER PRIMARY KEY AUTOINCREMENT). Entries are already in stored form (LogEntry.withoutLiveObjects). A batch is best saved in one transaction; the sink passes the next one only after this one completes. The base sends LogEntriesAdded.override -
queryEntries(
[LogQuery query = const LogQuery()]) → Future< LogPage> -
A page of entries for
query(onQueryEntries). Throws StateError after close.inherited -
queryTags(
) → Future< Set< String> > -
Tags of stored entries (onQueryTags). Throws StateError after close.
inherited
-
removeBefore(
DateTime time) → Future< void> -
Removes entries strictly before
time(onRemoveBefore) and sends LogEntriesRemovedBefore. Throws StateError after close.inherited -
reportChange(
LogStoreChange change) → void -
Reports a change the store made on its own: removed entries because of
file size (LogEntriesRemovedById or, if it does not know which,
LogStoreInvalidated). During onWriteEntries the change is sent after
the LogEntriesAdded of that write: otherwise a subscriber would get a
removal of entries it does not yet know about.
inherited
-
retainNewest(
int count) → Future< void> -
Keeps the
countnewest entries (onRetainNewest) and sends LogEntriesRemovedById with the removed ids, nothing if there was nothing to remove, or LogStoreInvalidated if the store does not know what it removed. Throws StateError after close.inherited -
toString(
) → String -
A string representation of this object.
inherited
-
writeEntries(
List< LogEntry> entries) → Future<List< StoredLogEntry> > -
Converts entries to stored form, saves them (onWriteEntries) and sends
LogEntriesAdded to changes; changes the store reported while saving
(reportChange) follow it. Throws StateError after close.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- defaultLimit → const int
- Default limit: enough for a session viewed in the viewer, and small enough that a page with a rare filter (queryInMemory scans entries linearly) or memory does not become noticeable.