📝 document runtime sink file flush methods

This commit is contained in:
Nanaloveyuki
2026-06-13 23:11:39 +08:00
parent a3ecb6676d
commit c8e4cee9d6
3 changed files with 150 additions and 0 deletions
+2
View File
@@ -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)
+74
View File
@@ -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.
+74
View File
@@ -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.