diff --git a/docs/api/file-sink-policy.md b/docs/api/file-sink-policy.md new file mode 100644 index 0000000..4b9db3b --- /dev/null +++ b/docs/api/file-sink-policy.md @@ -0,0 +1,79 @@ +--- +name: file-sink-policy +group: api +category: sink +update-time: 20260613 +description: Public file policy alias used by file sinks and configured runtime file controls. +key-word: + - file + - policy + - alias + - public +--- + +## File-sink-policy + +`FileSinkPolicy` is the public policy object used to describe file append mode, auto-flush behavior, and optional rotation settings together. It is a direct alias to the file policy model shared by `FileSink`, `ConfiguredLogger`, and file policy JSON helpers. + +### Interface + +```moonbit +pub type FileSinkPolicy = @utils.FileSinkPolicy +``` + +#### output + +- `FileSinkPolicy` - Public file policy object containing `append`, `auto_flush`, and optional `rotation` settings. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- This is a type alias, not a separate runtime wrapper. +- The current policy fields are `append : Bool`, `auto_flush : Bool`, and `rotation : FileRotation?`. +- The same policy object is returned by `FileSink::policy()` and `ConfiguredLogger::file_policy()`. +- It is also accepted by `FileSink::set_policy(...)` and `ConfiguredLogger::file_set_policy(...)`. + +### How to Use + +Here are some specific examples provided. + +#### When Need One Object For Runtime File Settings + +When append, flush, and rotation behavior should be updated together: +```moonbit +let policy = FileSinkPolicy::new( + append=false, + auto_flush=true, + rotation=Some(file_rotation(1024 * 1024, max_backups=3)), +) +``` + +In this example, the file policy can be passed around as one typed value instead of separate flags. + +#### When Need Runtime Policy Roundtrip + +When current file behavior should be read, adjusted, and written back: +```moonbit +let policy = logger.file_policy() +let next = FileSinkPolicy::new( + append=policy.append, + auto_flush=false, + rotation=policy.rotation, +) +``` + +In this example, the policy object is the handoff boundary for runtime file control. + +### Error Case + +e.g.: +- `FileSinkPolicy` itself does not have a runtime failure mode. + +- If a non-file runtime sink exposes a fallback policy through file helpers, the object is still valid but does not reflect a live file handle. + +### Notes + +1. Use `FileSinkPolicy::new(...)` to construct this policy explicitly. + +2. Use `file_sink_policy_to_json(...)` or `stringify_file_sink_policy(...)` when the policy should be exported. diff --git a/docs/api/file-sink-state.md b/docs/api/file-sink-state.md new file mode 100644 index 0000000..fcf5a50 --- /dev/null +++ b/docs/api/file-sink-state.md @@ -0,0 +1,70 @@ +--- +name: file-sink-state +group: api +category: runtime +update-time: 20260613 +description: Public file state alias used for live file-sink snapshots and runtime diagnostics. +key-word: + - file + - state + - alias + - public +--- + +## File-sink-state + +`FileSinkState` is the public snapshot object used to describe the current state of a file sink. It is a direct alias to the file state model returned by `FileSink::state()` and configured runtime file inspection helpers. + +### Interface + +```moonbit +pub type FileSinkState = @utils.FileSinkState +``` + +#### output + +- `FileSinkState` - Public file state snapshot containing path, availability, policy flags, optional rotation, and failure counters. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- This is a type alias, not a live file handle wrapper. +- The current snapshot fields are `path`, `available`, `append`, `auto_flush`, `rotation`, `open_failures`, `write_failures`, `flush_failures`, and `rotation_failures`. +- `FileSink::state()` returns this object directly for a concrete file sink. +- `ConfiguredLogger::file_state()` also returns this type, including fallback snapshots for non-file runtime sinks. + +### How to Use + +Here are some specific examples provided. + +#### When Need A One-shot File Health Snapshot + +When file runtime diagnostics should be read as one object: +```moonbit +let state = sink.state() +``` + +In this example, availability, policy, and failure counters are captured together. + +#### When Need To Export File Diagnostics + +When a snapshot should be serialized for logs or support output: +```moonbit +println(stringify_file_sink_state(logger.file_state(), pretty=true)) +``` + +In this example, the typed snapshot becomes readable JSON without manual field assembly. + +### Error Case + +e.g.: +- `FileSinkState` itself does not have a runtime failure mode. + +- If the sink is unavailable, the snapshot still exists and reports `available=false` together with the current counters. + +### Notes + +1. Use this object for one-shot file diagnostics instead of many narrow reads. + +2. Use `RuntimeFileState` when queue-related file runtime context is also required. diff --git a/docs/api/index.md b/docs/api/index.md index 1496898..5cfca78 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -103,10 +103,13 @@ BitLogger API navigation. - [file-sink.md](./file-sink.md) - [file-rotation.md](./file-rotation.md) - [file-sink-policy-to-json.md](./file-sink-policy-to-json.md) +- [file-sink-policy.md](./file-sink-policy.md) - [stringify-file-sink-policy.md](./stringify-file-sink-policy.md) - [file-sink-state-to-json.md](./file-sink-state-to-json.md) +- [file-sink-state.md](./file-sink-state.md) - [stringify-file-sink-state.md](./stringify-file-sink-state.md) - [runtime-file-state-to-json.md](./runtime-file-state-to-json.md) +- [runtime-file-state.md](./runtime-file-state.md) - [stringify-runtime-file-state.md](./stringify-runtime-file-state.md) - [sink-config.md](./sink-config.md) - [sink-config-to-json.md](./sink-config-to-json.md) diff --git a/docs/api/runtime-file-state.md b/docs/api/runtime-file-state.md new file mode 100644 index 0000000..7540d8d --- /dev/null +++ b/docs/api/runtime-file-state.md @@ -0,0 +1,76 @@ +--- +name: runtime-file-state +group: api +category: runtime +update-time: 20260613 +description: Public combined file-and-queue runtime state alias used by configured logger diagnostics. +key-word: + - runtime + - file + - state + - public +--- + +## Runtime-file-state + +`RuntimeFileState` is the public snapshot object that combines file state with queue runtime context for configured loggers. It is a direct alias to the runtime model used by configured file diagnostics and JSON export helpers. + +### Interface + +```moonbit +pub type RuntimeFileState = @utils.RuntimeFileState +``` + +#### output + +- `RuntimeFileState` - Public combined runtime snapshot containing a `file` snapshot plus queue metadata such as `queued`, `pending_count`, and `dropped_count`. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- This is a type alias, not a live runtime controller. +- The current fields are `file : FileSinkState`, `queued : Bool`, `pending_count : Int`, and `dropped_count : Int`. +- This type is returned by `ConfiguredLogger::file_runtime_state()` when the configured sink can expose file runtime context. +- It is broader than `FileSinkState` because it also reports whether queue wrapping is involved and how the queue is behaving. + +### How to Use + +Here are some specific examples provided. + +#### When Need Combined File And Queue Diagnostics + +When a configured logger may wrap a file sink in a queue: +```moonbit +match logger.file_runtime_state() { + Some(snapshot) => println(snapshot.pending_count) + None => () +} +``` + +In this example, queue backlog can be inspected alongside the embedded file state. + +#### When Need A Single Exportable Runtime Snapshot + +When runtime support output should include both file and queue context: +```moonbit +match logger.file_runtime_state() { + Some(snapshot) => println(stringify_runtime_file_state(snapshot, pretty=true)) + None => () +} +``` + +In this example, one typed object covers both the file snapshot and queue counters. + +### Error Case + +e.g.: +- `RuntimeFileState` itself does not have a runtime failure mode. + +- If the configured logger is not file-backed, `file_runtime_state()` may return `None` instead of producing this snapshot. + +### Notes + +1. Use this type when queued-file diagnostics matter, not just raw file status. + +2. Use `runtime_file_state_to_json(...)` or `stringify_runtime_file_state(...)` when the snapshot should be exported.