Repository navigation
Description
Context
While applying the assembly-owned sink flush pattern from #328 and #335 to a multi-channel production service (general, statement, ingest, compaction, and metering), we audited what Append::flush and Logger::flush actually do across all 10 built-in Append implementations in Logforth:
- 7 of 10 built-in appenders perform no user-space buffering at all:
Testing,Journald(UnixDatagram), andPosixSyslog(libc::syslog) have literalOk(())flush()implementations.Stderrwraps unbufferedstd::io::Stderr(StderrRaw::flushisOk(())).Stdoutappendsb'\n'beforewrite_all, which already flushesstd::io::Stdout'sLineWriteron every record.File(RollingFileWriter) writes directly to an unbufferedstd::fs::File, whoseWrite::flushinstdis a no-opOk(()).SocketSysloguses unbuffered datagram/stream sockets, andTcpTlsSender::sendalready callswrite_all(...).and_then(|()| stream.flush())per frame.
- 2 of 10 built-in appenders delegate to external telemetry runtimes whose lifecycles live outside
Logger:FastraceEvent::flushcalls globalfastrace::flush(), coupling a per-span event appender to the process-wide trace collector lifecycle.OpentelemetryLog::flushcallsSdkLoggerProvider::force_flush(), whereas callers already construct and retainSdkLoggerProviderto callprovider.shutdown()at exit (and sharing one provider across multipleOpentelemetryLogscopes triggers redundantforce_flush()calls when driven viaAppend::flush).
Asyncis the only built-in appender with an internal Logforth buffer, and its currentDroplifecycle breaks understaticloggers:Asynccurrently ownsJoinHandle<()>directly, makingAsync!Clone(requiringArc<Async>for multi-logger sharing).- When
Loggerinstances are stored inOnceLock/LazyLockstatics (as inexamples/src/multi_logger_pipeline.rs) or installed globally viaLogBridge::install(),Async::dropnever runs at process exit, so the background worker thread is never joined on shutdown.
Candidate Redesign Ahead of 1.0
Separating Async into a Clone sender handle plus an RAII #[must_use] AsyncGuard (AsyncBuilder::build(self) -> Result<(Async, AsyncGuard), Error>, analogous to tracing_appender::non_blocking's (NonBlocking, WorkerGuard)) lets main deterministically drain the queue and join the worker thread on exit even when Logger handles live in statics.
With AsyncGuard and SdkLoggerProvider owning async/batch teardown at the initialization boundary, we can evaluate two stacked steps for logforth-core:
- Step 1 (Plan B — Remove
Logger::flush, keep defaultedAppend::flush):- Remove
Logger::flushsoLoggeris strictly a non-owning emission handle (enabled,log), matching Golog/slog, SLF4J, .NETILogger, andtracing(LogBridge'slog::Log::flushbecomes a no-op liketracing-log). - Split
Asyncinto(Async, AsyncGuard)(Async: Clone,AsyncGuard::flush(&self)+ deterministic shutdown/join onDrop). - Default
Append::flush(&self) -> Result<(), Error>toOk(()), dropping no-op and cross-signalflushimplementations (Testing,Stderr,File,Journald,PosixSyslog,FastraceEvent) while preservingAsync's ability to flush custom buffered innerBox<dyn Append>implementations.
- Remove
- Step 2 (Plan A — Also remove
Append::flush):- Remove
Append::flushcompletely soAppendbecomes a single-method trait (fn append(&self, record: &Record, diags: &dyn Diagnostic) -> Result<(), Error>). - Synchronous appenders write complete records per
appendcall; any buffered, asynchronous, or batching sink (AsyncGuard,SdkLoggerProvider, or a custom batching sink's own guard) manages flushing and shutdown explicitly via RAII drop order inmain.
- Remove
Activity