Repository navigation
Conversation
…flush Remove `Logger::flush` so `Logger` acts strictly as a non-owning event emission handle (`LogBridge`'s `log::Log::flush` becomes a no-op). Split `AsyncBuilder::build` into `(Async, AsyncGuard)` so `Async` implements `Clone` directly while `AsyncGuard` deterministically drains queued records and joins the worker thread on `Drop` even when loggers live in `static`s. Provide a default `Ok(())` body on `Append::flush` and drop no-op and cross-signal `flush` overrides. Signed-off-by: tison <wander4096@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
PR Stack (
#338exploration)Logger::flush, splitAsyncBuilder::buildinto(Async, AsyncGuard), and defaultAppend::flushtoOk(()).Append::flushfromAppendaltogether.Refs #338.
Problem
Logger::flushconflates event emission with sink lifecycle ownership: When multiple channelLoggers share an underlyingAsyncorOpentelemetryLogsink, callingflush()on everyLoggertriggers redundant worker barriers or network export RPCs, while callers holding only aLoggermay flush shared or global resources (for example,FastraceEvent::flushpreviously flushed globalfastracetrace spans).Asynccould not shut down deterministically behindstaticloggers: Because Rust does not runDroponstaticitems (OnceLock<Logger>,LazyLock<Logger>, orLogBridge::install()), storingJoinHandle<()>directly insideAsyncpreventedAsyncfrom implementingCloneand causedAsync::drop(worker drain +join) to be skipped at process exit unless callers manually wired custom shutdown plumbing.Appendimplementations have no user-space buffer to flush: Requiring everyAppendimplementor to writefn flush(&self) -> Result<(), Error>forced boilerplateOk(())implementations across unbuffered sinks (Testing,Stderr,File,Journald,PosixSyslog).Solution
Logger::flush:Loggeris strictly a lightweight, non-owning emission handle.LogBridge'slog::Log::flushimplementation becomes a no-op{}(matchingtracing-log), while explicit sink lifecycle handles manage flushing and shutdown.#[must_use] AsyncGuardfromAsyncBuilder::build(Result<(Async, AsyncGuard), Error>):AsyncbecomesClonedirectly without wrapping inArc<Async>, allowing multipleDispatches orLoggers to share one background worker thread naturally.AsyncGuardexposesAsyncGuard::flush(&self) -> Result<(), Error>for on-demand synchronous queue draining and deterministically drains queued records, flushes inner appenders, and joins the worker thread onDrop(including safe non-blocking handling if dropped re-entrantly on the worker thread itself). Binding_guardinmainguarantees clean drain on exit even whenLoggerhandles live instatics.Append::flushtoOk(())and prune no-op / cross-signal overrides:Append::flushdefaults toOk(())so unbuffered appenders (Testing,Stderr,File,Journald,PosixSyslog, andFastraceEvent) omitflushboilerplate, andFastraceEventno longer triggers globalfastrace::flush()trace export as a side effect of log flushing.Stdout,SocketSyslog,OpentelemetryLog,Async,Arc<T>, and&'static Tcontinue forwarding or implementingAppend::flush.examples/src/multi_logger_pipeline.rsand README snippets to bind_guard: AsyncGuard(orprovider.shutdown()) at the application entry point instead of callinglogger.flush().