From 10555b3580d50ab3fea9153e292c782729bcd1a5 Mon Sep 17 00:00:00 2001 From: Nanaloveyuki Date: Sat, 13 Jun 2026 23:19:03 +0800 Subject: [PATCH] :memo: document runtime sink file state --- docs/api/index.md | 2 + docs/api/runtime-sink-file-runtime-state.md | 77 +++++++++++++++++++++ docs/api/runtime-sink-file-state.md | 74 ++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 docs/api/runtime-sink-file-runtime-state.md create mode 100644 docs/api/runtime-sink-file-state.md diff --git a/docs/api/index.md b/docs/api/index.md index 070c78b..edecd96 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -386,6 +386,8 @@ BitLogger API navigation. - [runtime-sink-file-policy.md](./runtime-sink-file-policy.md) - [runtime-sink-file-default-policy.md](./runtime-sink-file-default-policy.md) - [runtime-sink-file-policy-matches-default.md](./runtime-sink-file-policy-matches-default.md) +- [runtime-sink-file-state.md](./runtime-sink-file-state.md) +- [runtime-sink-file-runtime-state.md](./runtime-sink-file-runtime-state.md) - [configured-logger.md](./configured-logger.md) - [configured-logger-flush.md](./configured-logger-flush.md) - [configured-logger-drain.md](./configured-logger-drain.md) diff --git a/docs/api/runtime-sink-file-runtime-state.md b/docs/api/runtime-sink-file-runtime-state.md new file mode 100644 index 0000000..f173f8a --- /dev/null +++ b/docs/api/runtime-sink-file-runtime-state.md @@ -0,0 +1,77 @@ +--- +name: runtime-sink-file-runtime-state +group: api +category: runtime +update-time: 20260613 +description: Read combined file and queue runtime state from a RuntimeSink when it is backed by a file sink. +key-word: + - runtime + - sink + - file + - public +--- + +## Runtime-sink-file-runtime-state + +Read combined file and queue runtime state from a `RuntimeSink`. This helper is the richest file-specific diagnostics API on direct runtime sink values. + +### Interface + +```moonbit +pub fn RuntimeSink::file_runtime_state(self : RuntimeSink) -> RuntimeFileState? { +``` + +#### input + +- `self : RuntimeSink` - Runtime sink whose file runtime state should be inspected. + +#### output + +- `RuntimeFileState?` - Combined file and queue diagnostics when the runtime sink is file-backed, otherwise `None`. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- Plain `File` runtime variants return `Some(RuntimeFileState::new(sink.state()))`, so queue metadata stays at its default non-queued shape. +- `QueuedFile` runtime variants return `Some(RuntimeFileState)` with the wrapped file state plus `queued=true`, `pending_count=sink.pending_count()`, and `dropped_count=sink.dropped_count()`. +- Non-file runtime variants return `None`. +- This helper is richer than `file_state()` because it can also surface queued backlog and dropped counts. + +### How to Use + +Here are some specific examples provided. + +#### When Need Rich File Runtime Diagnostics + +When support output should include both file and queue state: +```moonbit +let state = sink.file_runtime_state() +``` + +In this example, callers can inspect availability, failure counters, and queue metrics together. + +#### When Need To Branch On File-backed Runtime Shape + +When code should behave differently for file-backed direct sinks: +```moonbit +match sink.file_runtime_state() { + Some(state) => ignore(state) + None => () +} +``` + +In this example, the optional return value reflects whether the runtime sink is file-backed. + +### Error Case + +e.g.: +- If the runtime sink is not file-backed, the method returns `None`. + +- If callers only need raw file status without queue context, `file_state()` may be the simpler API. + +### Notes + +1. Use this helper for the richest file-backed runtime diagnostics on direct sink values. + +2. It is especially useful for queued file sinks where file health and queue state both matter. diff --git a/docs/api/runtime-sink-file-state.md b/docs/api/runtime-sink-file-state.md new file mode 100644 index 0000000..c11921e --- /dev/null +++ b/docs/api/runtime-sink-file-state.md @@ -0,0 +1,74 @@ +--- +name: runtime-sink-file-state +group: api +category: runtime +update-time: 20260613 +description: Read the current file sink snapshot from a RuntimeSink. +key-word: + - runtime + - sink + - file + - public +--- + +## Runtime-sink-file-state + +Read the current file sink snapshot from a `RuntimeSink`. This helper exposes path, availability, policy flags, rotation config, and failure counters as one object. + +### Interface + +```moonbit +pub fn RuntimeSink::file_state(self : RuntimeSink) -> FileSinkState { +``` + +#### input + +- `self : RuntimeSink` - Runtime sink whose file state snapshot should be inspected. + +#### output + +- `FileSinkState` - Current file sink snapshot. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- Plain `File` runtime variants return a live snapshot from the wrapped `FileSink`. +- `QueuedFile` runtime variants forward the snapshot from the wrapped inner `FileSink`. +- Non-file runtime variants return a fallback empty-style state with `path=""`, `available=false`, `append=false`, `auto_flush=false`, `rotation=None`, and all failure counters set to `0`. +- This helper is broader than individual file counters or policy accessors because it aggregates core file status into one read. + +### How to Use + +Here are some specific examples provided. + +#### When Need A Full File Health Snapshot + +When diagnostics should inspect direct runtime file state as one object: +```moonbit +let state = sink.file_state() +``` + +In this example, callers receive a single file-state snapshot instead of querying each property separately. + +#### When Need To Export File Runtime Diagnostics + +When a support path should serialize current file state: +```moonbit +println(stringify_file_sink_state(sink.file_state(), pretty=true)) +``` + +In this example, the runtime sink snapshot can be exported directly through existing JSON helpers. + +### Error Case + +e.g.: +- If the runtime sink is not file-backed, the returned snapshot is a fallback empty-style state rather than a live file view. + +- If callers also need queue context for queued file sinks, `file_runtime_state()` is the richer API. + +### Notes + +1. Use this helper for the main one-shot file status snapshot. + +2. Prefer it over individual counters when broader file diagnostics are needed.