📝 document runtime sink file policies

This commit is contained in:
Nanaloveyuki
2026-06-13 23:16:37 +08:00
parent 419b79ac50
commit 793e9bfc83
5 changed files with 305 additions and 0 deletions
+4
View File
@@ -382,6 +382,10 @@ BitLogger API navigation.
- [runtime-sink-file-flush-failures.md](./runtime-sink-file-flush-failures.md)
- [runtime-sink-file-rotation-failures.md](./runtime-sink-file-rotation-failures.md)
- [runtime-sink-file-reset-failure-counters.md](./runtime-sink-file-reset-failure-counters.md)
- [runtime-sink-file-reset-policy.md](./runtime-sink-file-reset-policy.md)
- [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)
- [configured-logger.md](./configured-logger.md)
- [configured-logger-flush.md](./configured-logger-flush.md)
- [configured-logger-drain.md](./configured-logger-drain.md)
@@ -0,0 +1,74 @@
---
name: runtime-sink-file-default-policy
group: api
category: runtime
update-time: 20260613
description: Read the initial default file policy associated with a RuntimeSink.
key-word:
- runtime
- sink
- file
- public
---
## Runtime-sink-file-default-policy
Read the initial default file policy associated with a `RuntimeSink`. This helper exposes the baseline file policy captured when the runtime sink was created.
### Interface
```moonbit
pub fn RuntimeSink::file_default_policy(self : RuntimeSink) -> FileSinkPolicy {
```
#### input
- `self : RuntimeSink` - Runtime sink whose default file policy should be inspected.
#### output
- `FileSinkPolicy` - Initial default file policy.
### Explanation
Detailed rules explaining key parameters and behaviors
- Plain `File` runtime variants return the default policy captured at creation time.
- `QueuedFile` runtime variants forward the default policy from the wrapped inner `FileSink`.
- Non-file runtime variants return the neutral fallback policy `FileSinkPolicy::new(append=false, auto_flush=false, rotation=None)`.
- This helper is useful when callers need to compare runtime drift or restore defaults later.
### How to Use
Here are some specific examples provided.
#### When Need Baseline Policy Visibility
When diagnostics should show the original file policy separately from the live one:
```moonbit
let defaults = sink.file_default_policy()
```
In this example, the runtime sink exposes its original file policy snapshot.
#### When Prepare For Policy Reset Logic
When tooling should capture or compare default settings explicitly:
```moonbit
let original = sink.file_default_policy()
```
In this example, callers can reason about factory file policy separately from runtime changes.
### Error Case
e.g.:
- If the runtime sink is not file-backed, the return value is a neutral fallback policy.
- If callers only need to know whether runtime drift exists, `file_policy_matches_default()` is the simpler API.
### Notes
1. Use this helper when the original file policy matters operationally.
2. It complements `file_policy()` and `file_reset_policy()`.
@@ -0,0 +1,76 @@
---
name: runtime-sink-file-policy-matches-default
group: api
category: runtime
update-time: 20260613
description: Read whether the current runtime file policy still matches the RuntimeSink default policy.
key-word:
- runtime
- sink
- file
- public
---
## Runtime-sink-file-policy-matches-default
Read whether the current runtime file policy still matches the default policy of a `RuntimeSink`. This helper is useful for detecting operational drift on direct sink values.
### Interface
```moonbit
pub fn RuntimeSink::file_policy_matches_default(self : RuntimeSink) -> Bool {
```
#### input
- `self : RuntimeSink` - Runtime sink whose runtime policy drift should be checked.
#### output
- `Bool` - Whether the current runtime file policy still matches the default.
### Explanation
Detailed rules explaining key parameters and behaviors
- Plain `File` runtime variants compare current runtime file policy against their stored defaults.
- `QueuedFile` runtime variants forward the comparison from the wrapped inner `FileSink`.
- Non-file runtime variants return `false`.
- This helper is a compact drift signal when callers do not need to compare full policy objects directly.
### How to Use
Here are some specific examples provided.
#### When Need Drift Detection
When diagnostics should report whether file policy changed after startup:
```moonbit
let unchanged = sink.file_policy_matches_default()
```
In this example, the runtime sink exposes whether runtime file policy still matches the baseline.
#### When Gate Reset Logic
When code should only reset policy if drift exists:
```moonbit
if !sink.file_policy_matches_default() {
ignore(sink.file_reset_policy())
}
```
In this example, policy reset only happens when runtime state diverged from defaults.
### Error Case
e.g.:
- If the runtime sink is not file-backed, the method returns `false`.
- If callers need the exact differences instead of a boolean drift signal, they should inspect both `file_policy()` and `file_default_policy()`.
### Notes
1. Use this helper for compact runtime policy drift checks.
2. It is especially useful before calling reset-style operations.
+75
View File
@@ -0,0 +1,75 @@
---
name: runtime-sink-file-policy
group: api
category: runtime
update-time: 20260613
description: Read the current runtime file policy from a RuntimeSink.
key-word:
- runtime
- sink
- file
- public
---
## Runtime-sink-file-policy
Read the current runtime file policy from a `RuntimeSink`. This helper exposes the active append, auto-flush, and rotation settings as one policy object.
### Interface
```moonbit
pub fn RuntimeSink::file_policy(self : RuntimeSink) -> FileSinkPolicy {
```
#### input
- `self : RuntimeSink` - Runtime sink whose current file policy should be inspected.
#### output
- `FileSinkPolicy` - Current runtime file policy.
### Explanation
Detailed rules explaining key parameters and behaviors
- Plain `File` runtime variants return the current policy from the wrapped `FileSink`.
- `QueuedFile` runtime variants forward the policy from the wrapped inner `FileSink`.
- Non-file runtime variants return the neutral fallback policy `FileSinkPolicy::new(append=false, auto_flush=false, rotation=None)`.
- This helper is broader than `file_append_mode()` or `file_auto_flush()` because it returns the whole policy object.
### How to Use
Here are some specific examples provided.
#### When Need Full Runtime Policy Visibility
When diagnostics should inspect the active file policy as one object:
```moonbit
let policy = sink.file_policy()
```
In this example, append, flush, and rotation settings are read together from the runtime sink.
#### When Compare Current And Default Policy
When runtime drift from defaults should be inspected explicitly:
```moonbit
let current = sink.file_policy()
let defaults = sink.file_default_policy()
```
In this example, callers can compare current runtime settings with the initial policy snapshot.
### Error Case
e.g.:
- If the runtime sink is not file-backed, the return value is a neutral fallback policy rather than a real active file policy.
- If callers only need one field from the policy, a narrower helper may be simpler.
### Notes
1. Use this helper when file policy should be handled as one object.
2. Pair it with `file_set_policy(...)` for roundtrip-style policy management.
@@ -0,0 +1,76 @@
---
name: runtime-sink-file-reset-policy
group: api
category: runtime
update-time: 20260613
description: Reset the runtime file policy of a file-backed RuntimeSink back to its original defaults.
key-word:
- runtime
- sink
- file
- public
---
## Runtime-sink-file-reset-policy
Reset the runtime file policy of a `RuntimeSink` back to its original defaults. This helper restores append, auto-flush, and rotation policy together on direct sink values.
### Interface
```moonbit
pub fn RuntimeSink::file_reset_policy(self : RuntimeSink) -> Bool {
```
#### input
- `self : RuntimeSink` - Runtime sink whose file policy should be restored.
#### output
- `Bool` - Whether the reset was applied.
### Explanation
Detailed rules explaining key parameters and behaviors
- Plain `File` runtime variants restore their stored default file policy and return `true`.
- `QueuedFile` runtime variants forward the reset behavior to the wrapped inner `FileSink` and return `true`.
- Non-file runtime variants return `false`.
- This helper is the inverse of runtime policy drift, not a generic reopen or flush action.
### How to Use
Here are some specific examples provided.
#### When Need To Undo Runtime Policy Changes
When file policy should return to the original defaults captured by the runtime sink:
```moonbit
ignore(sink.file_reset_policy())
```
In this example, append, auto-flush, and rotation settings are restored together.
#### When Use Drift-aware Recovery
When reset should only happen after runtime changes:
```moonbit
if !sink.file_policy_matches_default() {
ignore(sink.file_reset_policy())
}
```
In this example, reset is only applied when runtime policy has diverged.
### Error Case
e.g.:
- If the runtime sink is not file-backed, the method returns `false`.
- If callers need to restore only one setting, a narrower setter may be more appropriate than a full policy reset.
### Notes
1. Use this helper when the original bundled file policy should be restored intact.
2. It pairs naturally with `file_policy_matches_default()` and `file_default_policy()`.