Async-logger-config-to-json
Convert a typed AsyncLoggerConfig into a JsonValue. This helper exports async queue capacity, overflow policy, batch sizing, linger timing, and flush behavior in a structured form.
Interface
pub fn async_logger_config_to_json(config : AsyncLoggerConfig) -> @json_parser.JsonValue {}input
config : AsyncLoggerConfig- Async logger runtime config to export.
output
JsonValue- Structured JSON representation of the async config.
Explanation
Detailed rules explaining key parameters and behaviors
- The output includes
max_pending,max_batch,linger_ms,overflow, andflush. - Policy fields are serialized using the stable labels accepted by the config parser.
- This helper exports effective typed config after constructor normalization has already happened.
- If
max_pendingis negative in the config object, the exported JSON preserves that negative value because runtime queue clamping happens later, not during serialization. - The JSON shape matches the
async_configsection used by async build config parsing.
How to Use
Here are some specific examples provided.
When Need Structured Async Config Export
When async runtime policy should be embedded in a larger JSON payload:
let async_json = async_logger_config_to_json(
AsyncLoggerConfig::new(max_pending=128, max_batch=8),
)In this example, callers receive a machine-readable config value.
When Need Roundtrip-friendly Async Settings
When code generates async policy and later persists it:
let value = async_logger_config_to_json(AsyncLoggerConfig::new(flush=AsyncFlushPolicy::Batch))In this example, the exported JSON stays aligned with parser expectations.
Error Case
e.g.:
If
max_batchorlinger_mswere normalized during construction, the exported JSON reflects the normalized values rather than the original invalid inputs.If callers need to understand runtime queue behavior for negative
max_pending, they should document that separately because serialization preserves the config value rather than the later queue-kind clamp.If callers want direct text output instead of a JSON value, they should use
stringify_async_logger_config(...)instead.
Notes
Serialized policy labels round-trip through
parse_async_logger_config_text(...).The serializer emits canonical labels like
DropNewestandNever, even though the parser also accepts compatibility aliases such asDropLatestandNone.