3.0 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| configured-logger-file-set-policy | api | runtime | 20260707 | Apply a bundled runtime file policy update to a configured file-backed logger. |
|
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.
The input FileSinkPolicy value is owned by src/file_model; this configured-logger surface is a facade over Logger[@runtime.RuntimeSink] and delegates policy mutation to the wrapped RuntimeSink.
Interface
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 through the wrapped
RuntimeSink. - Queued file sinks forward the policy update to the wrapped inner file sink only when no queued records are pending.
- The accepted policy object itself is the shared
@file_model.FileSinkPolicymodel, not a configured-logger-owned concrete type. - Non-file sinks return
false. - This helper is broader than the single-setting setters because it updates the whole file policy in one call.
- If a queued file sink still has pending records, the update is rejected and returns
falseso already queued records are not later written under a different policy bundle than the one they were queued under.
How to Use
Here are some specific examples provided.
When Need Bundled Runtime Policy Changes
When append, flush, and rotation should change together:
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:
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(...)orfile_set_rotation(...)may be clearer. -
If a queued file sink still has pending records, callers should flush or close it first before changing policy.
Notes
-
Use this helper when the runtime policy should be treated as one cohesive object.
-
On queued file sinks, clear pending records first so policy mutation does not retroactively affect already queued writes.