From c8e4cee9d6c52180cbe8e3aa5c41e617b2e77c4f Mon Sep 17 00:00:00 2001 From: Nanaloveyuki Date: Sat, 13 Jun 2026 23:11:39 +0800 Subject: [PATCH] :memo: document runtime sink file flush methods --- docs/api/index.md | 2 + docs/api/runtime-sink-file-close.md | 74 +++++++++++++++++++++++++++++ docs/api/runtime-sink-file-flush.md | 74 +++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 docs/api/runtime-sink-file-close.md create mode 100644 docs/api/runtime-sink-file-flush.md diff --git a/docs/api/index.md b/docs/api/index.md index c663da7..901ed75 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -375,6 +375,8 @@ BitLogger API navigation. - [runtime-sink-file-rotation-config.md](./runtime-sink-file-rotation-config.md) - [runtime-sink-file-set-rotation.md](./runtime-sink-file-set-rotation.md) - [runtime-sink-file-clear-rotation.md](./runtime-sink-file-clear-rotation.md) +- [runtime-sink-file-flush.md](./runtime-sink-file-flush.md) +- [runtime-sink-file-close.md](./runtime-sink-file-close.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-close.md b/docs/api/runtime-sink-file-close.md new file mode 100644 index 0000000..c67e751 --- /dev/null +++ b/docs/api/runtime-sink-file-close.md @@ -0,0 +1,74 @@ +--- +name: runtime-sink-file-close +group: api +category: runtime +update-time: 20260613 +description: Close the file sink behind a RuntimeSink when one is present. +key-word: + - runtime + - sink + - file + - public +--- + +## Runtime-sink-file-close + +Close the file sink behind a `RuntimeSink`. This helper is the direct file-specific runtime close surface for code that owns a sink value instead of a `ConfiguredLogger`. + +### Interface + +```moonbit +pub fn RuntimeSink::file_close(self : RuntimeSink) -> Bool { +``` + +#### input + +- `self : RuntimeSink` - Runtime sink whose file sink should be closed. + +#### output + +- `Bool` - Whether the underlying file close succeeded. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- Plain `File` runtime variants forward directly to `FileSink::close()`. +- `QueuedFile` runtime variants first attempt `sink.flush()` on the queue wrapper, then call `sink.sink.close()` on the wrapped file sink. +- For `QueuedFile`, the queue flush result is ignored and the returned `Bool` comes from the inner file close. +- Non-file runtime variants return `false`. + +### How to Use + +Here are some specific examples provided. + +#### When Need Direct File-specific Runtime Teardown + +When code holds a file-backed `RuntimeSink` directly and should close its file handle explicitly: +```moonbit +ignore(sink.file_close()) +``` + +In this example, file teardown happens through the runtime sink itself. + +#### When Need A File-specific Close Result + +When application code wants the direct file close outcome: +```moonbit +let closed = sink.file_close() +``` + +In this example, the result describes file close behavior rather than generic sink close behavior. + +### Error Case + +e.g.: +- If the runtime sink is not file-backed, the method returns `false`. + +- If callers only need generic sink teardown, `close()` is the broader API. + +### Notes + +1. Prefer this helper when direct runtime code specifically cares about file-backed shutdown. + +2. Queued file sinks may flush pending records before closing the file. diff --git a/docs/api/runtime-sink-file-flush.md b/docs/api/runtime-sink-file-flush.md new file mode 100644 index 0000000..6565445 --- /dev/null +++ b/docs/api/runtime-sink-file-flush.md @@ -0,0 +1,74 @@ +--- +name: runtime-sink-file-flush +group: api +category: runtime +update-time: 20260613 +description: Flush the file sink behind a RuntimeSink when one is present. +key-word: + - runtime + - sink + - file + - public +--- + +## Runtime-sink-file-flush + +Flush the file sink behind a `RuntimeSink`. This helper is the direct file-specific runtime flush surface for code that owns a sink value instead of a `ConfiguredLogger`. + +### Interface + +```moonbit +pub fn RuntimeSink::file_flush(self : RuntimeSink) -> Bool { +``` + +#### input + +- `self : RuntimeSink` - Runtime sink whose file sink should be flushed. + +#### output + +- `Bool` - Whether the underlying file flush succeeded. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- Plain `File` runtime variants forward directly to `FileSink::flush()`. +- `QueuedFile` runtime variants first attempt `sink.flush()` on the queue wrapper, then call `sink.sink.flush()` on the wrapped file sink. +- For `QueuedFile`, the queue flush result is ignored and the returned `Bool` comes from the inner file flush. +- Non-file runtime variants return `false`. + +### How to Use + +Here are some specific examples provided. + +#### When Need Explicit Direct File Durability Steps + +When code holds a file-backed `RuntimeSink` directly and should flush it explicitly: +```moonbit +ignore(sink.file_flush()) +``` + +In this example, the runtime sink attempts to flush its file-backed output directly. + +#### When Need A File-specific Success Flag + +When code should branch on the outcome of a direct file flush: +```moonbit +let ok = sink.file_flush() +``` + +In this example, callers can distinguish file flush success from a non-file sink shape. + +### Error Case + +e.g.: +- If the runtime sink is not file-backed, the method returns `false`. + +- If callers want generic queue or sink advancement instead of file-specific behavior, `flush()` is the broader API. + +### Notes + +1. Prefer this helper when direct runtime code specifically cares about file flush behavior. + +2. Queued file sinks may perform both queue flush work and file flush work here.