RemoteSyncLogOutput class

A structured_log sink that ships entries to a structured_log_server over HTTP (structured-log-http-sender).

Plugs in wherever an OutputFunction is expected, because it is one — calling the instance enqueues an entry and returns immediately, so a slow or unreachable server never blocks the code that logged:

final output = RemoteSyncLogOutput(
  serverUrl: 'https://logs.example.com',
  projectSecretKey: 'slk_...',
);
StructlogConfiguration.configure(
  sinks: [LogSink(name: 'server', output: output)],
);

getLogger().info('startup');
await output.flushed; // before the process exits

Entries accumulate until batchSize of them are waiting or batchTimeout elapses, whichever comes first, and then travel as one POST /v1/logs. Sends are serialized through a single chained future the way AsyncFileOutput serializes writes, so two batches are never in flight at once and their order is the order they were logged in.

Constructors

RemoteSyncLogOutput({required String serverUrl, required String projectSecretKey, int batchSize = 50, Duration batchTimeout = const Duration(seconds: 5), int maxBufferedEntries = 10000, int maxAttempts = 4, Duration retryBackoff = const Duration(milliseconds: 500), Duration maxRetryAfter = const Duration(minutes: 5), Duration requestTimeout = const Duration(seconds: 30), BatchSender? sender, void report(String message)?})
A sender replaces the HTTP transport entirely — it exists so the batching, retry and eviction behaviour can be driven in tests without a socket, and a caller who supplies one owns its lifetime.
factory

Properties

batchSize → int
Entries that trigger a send without waiting for batchTimeout.
final
batchTimeout → Duration
How long a partial batch waits before going out anyway.
final
flushed → Future<void>
Completes once everything enqueued before this call has been delivered or definitively given up on (retries exhausted, or a non-retryable answer). Await it before the process exits.
no setter
hashCode → int
The hash code for this object.
no setterinherited
maxAttempts → int
Attempts per batch, including the first. Only retryable outcomes are retried.
final
maxBufferedEntries → int
How many entries may wait in memory. Past this the oldest are dropped — an unreachable server must not turn into unbounded memory growth.
final
maxRetryAfter → Duration
Ceiling on a Retry-After this sink will honour. A longer one is clamped to this and reported, and Duration.zero switches honouring off entirely — the backoff then stands as it did before.
final
projectSecretKey → String
Sent as Authorization: Bearer <projectSecretKey> on every request.
final
requestTimeout → Duration
How long one HTTP attempt may take before it counts as a retryable failure.
final
retryBackoff → Duration
Delay before the second attempt; doubles for each attempt after that.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serverUrl → String
Base URL of the server; /v1/logs is appended.
final

Methods

call(Map<String, dynamic> entry, LogLevel level) → void
Enqueues entry. Returns immediately — this is the whole point of the sink, and the reason flushed exists.
close() → Future<void>
Stops accepting entries, sends whatever is buffered, and releases the HTTP client. Later calls are reported and discarded rather than silently swallowed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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