From d1260c5debcdfb2a73c1ad7dba17eac31e2ee69b Mon Sep 17 00:00:00 2001 From: Nanaloveyuki Date: Tue, 12 May 2026 14:58:22 +0800 Subject: [PATCH] :memo: Add configured logger file policy API docs --- .../configured-logger-file-default-policy.md | 74 +++++++++++++++++ ...ured-logger-file-policy-matches-default.md | 76 ++++++++++++++++++ docs/api/configured-logger-file-policy.md | 75 ++++++++++++++++++ .../configured-logger-file-reset-policy.md | 76 ++++++++++++++++++ docs/api/configured-logger-file-set-policy.md | 79 +++++++++++++++++++ 5 files changed, 380 insertions(+) create mode 100644 docs/api/configured-logger-file-default-policy.md create mode 100644 docs/api/configured-logger-file-policy-matches-default.md create mode 100644 docs/api/configured-logger-file-policy.md create mode 100644 docs/api/configured-logger-file-reset-policy.md create mode 100644 docs/api/configured-logger-file-set-policy.md diff --git a/docs/api/configured-logger-file-default-policy.md b/docs/api/configured-logger-file-default-policy.md new file mode 100644 index 0000000..85f3df6 --- /dev/null +++ b/docs/api/configured-logger-file-default-policy.md @@ -0,0 +1,74 @@ +--- +name: configured-logger-file-default-policy +group: api +category: runtime +update-time: 20260512 +description: Read the initial default file policy associated with a configured file-backed logger. +key-word: + - logger + - runtime + - file + - public +--- + +## Configured-logger-file-default-policy + +Read the initial default file policy associated with a `ConfiguredLogger`. This helper exposes the baseline file policy captured when the runtime sink was created. + +### Interface + +```moonbit +pub fn ConfiguredLogger::file_default_policy(self : ConfiguredLogger) -> FileSinkPolicy {} +``` + +#### input + +- `self : ConfiguredLogger` - Config-driven runtime logger whose default file policy should be inspected. + +#### output + +- `FileSinkPolicy` - Initial default file policy. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- File-backed sinks return the default policy captured at creation time. +- Queued file sinks forward the default policy from the wrapped file sink. +- Non-file sinks return a neutral fallback policy value. +- 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 = logger.file_default_policy() +``` + +In this example, the configured logger exposes its original file policy snapshot. + +#### When Prepare For Policy Reset Logic + +When tooling should capture or compare default settings explicitly: +```moonbit +let original = logger.file_default_policy() +``` + +In this example, callers can reason about “factory” file policy separately from runtime changes. + +### Error Case + +e.g.: +- If the configured 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()`. diff --git a/docs/api/configured-logger-file-policy-matches-default.md b/docs/api/configured-logger-file-policy-matches-default.md new file mode 100644 index 0000000..a511859 --- /dev/null +++ b/docs/api/configured-logger-file-policy-matches-default.md @@ -0,0 +1,76 @@ +--- +name: configured-logger-file-policy-matches-default +group: api +category: runtime +update-time: 20260512 +description: Read whether the current runtime file policy still matches the configured logger default policy. +key-word: + - logger + - runtime + - file + - public +--- + +## Configured-logger-file-policy-matches-default + +Read whether the current runtime file policy still matches the default policy of a `ConfiguredLogger`. This helper is useful for detecting operational drift. + +### Interface + +```moonbit +pub fn ConfiguredLogger::file_policy_matches_default(self : ConfiguredLogger) -> Bool {} +``` + +#### input + +- `self : ConfiguredLogger` - Config-driven runtime logger 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 + +- File-backed sinks compare current runtime file policy against their stored defaults. +- Queued file sinks forward the comparison from the wrapped file sink. +- Non-file sinks 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 = logger.file_policy_matches_default() +``` + +In this example, the configured logger exposes whether runtime file policy still matches the baseline. + +#### When Gate Reset Logic + +When code should only reset policy if drift exists: +```moonbit +if !logger.file_policy_matches_default() { + ignore(logger.file_reset_policy()) +} +``` + +In this example, policy reset only happens when runtime state diverged from defaults. + +### Error Case + +e.g.: +- If the configured 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. diff --git a/docs/api/configured-logger-file-policy.md b/docs/api/configured-logger-file-policy.md new file mode 100644 index 0000000..14f769f --- /dev/null +++ b/docs/api/configured-logger-file-policy.md @@ -0,0 +1,75 @@ +--- +name: configured-logger-file-policy +group: api +category: runtime +update-time: 20260512 +description: Read the current runtime file policy from a configured file-backed logger. +key-word: + - logger + - runtime + - file + - public +--- + +## Configured-logger-file-policy + +Read the current runtime file policy from a `ConfiguredLogger`. This helper exposes the active append, auto-flush, and rotation settings as one policy object. + +### Interface + +```moonbit +pub fn ConfiguredLogger::file_policy(self : ConfiguredLogger) -> FileSinkPolicy {} +``` + +#### input + +- `self : ConfiguredLogger` - Config-driven runtime logger whose current file policy should be inspected. + +#### output + +- `FileSinkPolicy` - Current runtime file policy. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- File-backed sinks return their current runtime file policy. +- Queued file sinks forward the policy from the wrapped file sink. +- Non-file sinks return a neutral fallback policy value. +- 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 = logger.file_policy() +``` + +In this example, append, flush, and rotation settings are read together. + +#### When Compare Current And Default Policy + +When runtime drift from defaults should be inspected explicitly: +```moonbit +let current = logger.file_policy() +let defaults = logger.file_default_policy() +``` + +In this example, callers can compare current runtime settings with the initial policy snapshot. + +### Error Case + +e.g.: +- If the configured 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. diff --git a/docs/api/configured-logger-file-reset-policy.md b/docs/api/configured-logger-file-reset-policy.md new file mode 100644 index 0000000..a3e797d --- /dev/null +++ b/docs/api/configured-logger-file-reset-policy.md @@ -0,0 +1,76 @@ +--- +name: configured-logger-file-reset-policy +group: api +category: runtime +update-time: 20260512 +description: Reset the runtime file policy of a configured file-backed logger back to its original defaults. +key-word: + - logger + - runtime + - file + - public +--- + +## Configured-logger-file-reset-policy + +Reset the runtime file policy of a `ConfiguredLogger` back to its original defaults. This helper restores append, auto-flush, and rotation policy together. + +### Interface + +```moonbit +pub fn ConfiguredLogger::file_reset_policy(self : ConfiguredLogger) -> Bool {} +``` + +#### input + +- `self : ConfiguredLogger` - Config-driven runtime logger whose file policy should be restored. + +#### output + +- `Bool` - Whether the reset was applied. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- File-backed sinks restore their stored default file policy. +- Queued file sinks forward the reset behavior to the wrapped file sink. +- Non-file sinks 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 configured defaults: +```moonbit +ignore(logger.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 !logger.file_policy_matches_default() { + ignore(logger.file_reset_policy()) +} +``` + +In this example, reset is only applied when runtime policy has diverged. + +### Error Case + +e.g.: +- If the configured 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()`. diff --git a/docs/api/configured-logger-file-set-policy.md b/docs/api/configured-logger-file-set-policy.md new file mode 100644 index 0000000..9b5fcd5 --- /dev/null +++ b/docs/api/configured-logger-file-set-policy.md @@ -0,0 +1,79 @@ +--- +name: configured-logger-file-set-policy +group: api +category: runtime +update-time: 20260512 +description: Apply a bundled runtime file policy update to a configured file-backed logger. +key-word: + - logger + - runtime + - file + - public +--- + +## Configured-logger-file-set-policy + +Apply a bundled runtime file policy update to a `ConfiguredLogger`. This helper updates append mode, auto-flush, and rotation together through one runtime policy object. + +### Interface + +```moonbit +pub fn ConfiguredLogger::file_set_policy(self : ConfiguredLogger, policy : FileSinkPolicy) -> Bool {} +``` + +#### input + +- `self : ConfiguredLogger` - Config-driven runtime logger whose file policy should change. +- `policy : FileSinkPolicy` - Bundled runtime file policy to apply. + +#### output + +- `Bool` - Whether the policy update was applied. + +### Explanation + +Detailed rules explaining key parameters and behaviors + +- File-backed sinks update append, auto-flush, and rotation together. +- Queued file sinks forward the policy update to the wrapped file sink. +- Non-file sinks return `false`. +- This helper is broader than the single-setting setters because it updates the whole file policy in one call. + +### How to Use + +Here are some specific examples provided. + +#### When Need Bundled Runtime Policy Changes + +When append, flush, and rotation should change together: +```moonbit +ignore(logger.file_set_policy(FileSinkPolicy::new( + append=true, + auto_flush=false, + rotation=Some(file_rotation(2048, max_backups=2)), +))) +``` + +In this example, runtime file behavior is updated as one policy change. + +#### When Apply A Policy Snapshot + +When a previously captured or computed policy should be restored: +```moonbit +let ok = logger.file_set_policy(policy) +``` + +In this example, callers can reapply a whole policy object without splitting it into separate setter calls. + +### Error Case + +e.g.: +- If the configured sink is not file-backed, the method returns `false`. + +- If callers only need to change one setting, a narrower setter such as `file_set_auto_flush(...)` or `file_set_rotation(...)` may be clearer. + +### Notes + +1. Use this helper when the runtime policy should be treated as one cohesive object. + +2. It pairs naturally with `file_policy()` and `file_default_policy()`.