Skip to content

refactor(core)!: remove Append::flush - #340

Draft
tisonkun wants to merge 1 commit into
refactor/remove-logger-flushfrom
refactor/remove-append-flush
Draft

tisonkun wants to merge 1 commit into
refactor/remove-logger-flushfrom
refactor/remove-append-flush

Conversation

@tisonkun

@tisonkun tisonkun commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Note

PR Stack (#338 exploration)

  1. refactor!: remove Logger::flush, add AsyncGuard, and default Append::flush #339 — Option B: Remove Logger::flush, split AsyncBuilder::build into (Async, AsyncGuard), and default Append::flush to Ok(()).
  2. This PR (Option A, stacked on refactor!: remove Logger::flush, add AsyncGuard, and default Append::flush #339): Remove Append::flush from Append altogether.

Refs #338.

Problem

Across all 10 built-in Append implementations in Logforth, 7 perform zero user-space buffering (Testing, Stderr, Stdout with trailing \n, File over raw std::fs::File, Journald, PosixSyslog, and SocketSyslog, whose stream senders already flush per record), 2 delegate to external SDKs that own their own lifecycle handles (fastrace::flush() and SdkLoggerProvider::force_flush() / shutdown()), and only Async buffers records internally in Logforth (whose queue lifecycle is now owned by AsyncGuard).

Keeping Append::flush on the core trait leaves an ambiguous second flush path alongside dedicated sink handles (AsyncGuard::flush / Drop and SdkLoggerProvider::force_flush / shutdown), while callers holding Box<dyn Append> or Logger have no sink-agnostic flush trigger once Logger::flush is removed.

Solution

  • Remove Append::flush from logforth_core::Append: Append becomes a single-method trait (fn append(&self, record: &Record, diags: &dyn Diagnostic) -> Result<(), Error>).
  • Remove remaining Append::flush implementations: Drop Append::flush from Arc<T>, &'static T, Stdout, SocketSyslog (Drop still flushes the underlying logforth_syslog::Sender), OpentelemetryLog (along with its now-redundant SdkLoggerProvider field), and Async (as well as flush_appends inside logforth-append-async).
  • Retain AsyncGuard::flush and AsyncGuard Drop drain: AsyncGuard::flush(&self) -> Result<(), Error> continues to enqueue a synchronous barrier on the worker queue until all preceding records are processed, and dropping AsyncGuard drains pending records and joins the worker thread.

Remove `Append::flush` from `logforth_core::Append` so `Append` becomes a single-method record sink trait (`Append::append`), and drop the now-redundant `SdkLoggerProvider` field from `OpentelemetryLog`. Sinks that buffer or batch out-of-band manage draining and teardown through their own dedicated lifecycle handles (`AsyncGuard` for `logforth-append-async` and `SdkLoggerProvider` for `logforth-append-opentelemetry`), eliminating ambiguous trait-level flush hooks.

Signed-off-by: tison <wander4096@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant