LogSink class final

The records of one app: the last capacity of them kept in a ring for listeners that come later (a console overlay), every one passed to the listeners as it comes and, with a path, appended to that file; while it serves, sent to the clients of its socket too.

A TwkApp has one, TwkApp.logs, which log writes to while the app runs. A sink of its own, its records read back:

final logs = LogSink(capacity: 100)
  ..addListener((record) => print(record.message));
logs.add(LogRecord(DateTime.now(), LogLevel.info, 'started'));
print(logs.records.length); // 1

See also:

  • log, which writes to the sink of the app it is called in.

Constructors

LogSink({int capacity = 1000, String? path})
An empty sink that keeps the last capacity records, 1000 by default, and appends each to the file path when one is given.

Properties

capacity → int
How many records are kept: when there are more, the oldest go.
final
hashCode → int
The hash code for this object.
no setterinherited
path → String?
The file every record is appended to (TWK_LOG for a TwkApp); on the web, which has no files, add throws UnsupportedError for one.
final
records → List<LogRecord>
The records kept, oldest first.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(LogRecord record) → void
Keeps record, dropping the oldest when the ring is full, writes it to path, then passes it to the listeners.
addListener(void listener(LogRecord record)) → void
Calls listener with every record added after this call, as it is added.
close() → Future<void>
Stops serving (serve): the clients are disconnected, the socket closed and the address file removed if it still holds this sink's address; one still starting is closed once it has. Does nothing when not serving.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeListener(void listener(LogRecord record)) → void
Stops calling listener, added with addListener; does nothing when it is not a listener. A listener removed while a record is passed to the listeners still gets that record.
run<R>(R body()) → R
Runs body with log and print writing to this sink, in body and in what it schedules, as they do in the TwkApp whose sink it is; returns what body returns. Only these: what body throws, it throws, and its errors reach whoever awaits them.
serve({String? directory}) → Future<LocalAddress>
Serves the records over a local socket (LocalAddress.bind) until close, for twk logs: a client that sends the address's token and a line feed gets the records kept, oldest first, then each one as it is added, as lines of JSON (LogRecord.toJson). The address goes to the address file .dart_tool/twk/logs of the project directory is in (LocalAddress.projectOf), in place of another app's. Returns the address; the one served already, or being started, when called again, so that one socket is served however many calls overlap. The socket keeps the process alive until close. What fails fails each call that waited for it, and the next call tries again. Throws UnsupportedError on the web, which has no local sockets.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited