📝 clarify async target override docs

This commit is contained in:
Nanaloveyuki
2026-06-14 07:34:31 +08:00
parent 38a5b056b8
commit 4b68ae27f1
6 changed files with 33 additions and 14 deletions
+14 -4
View File
@@ -3,7 +3,7 @@ name: async-logger-log
group: api
category: async
update-time: 20260614
description: Enqueue a record into the async logger with an explicit level, message, optional fields, and optional target override, using the repo's direct async call style.
description: Enqueue a record into the async logger with an explicit level, message, optional fields, and optional target override.
key-word:
- async
- logger
@@ -13,7 +13,7 @@ key-word:
## Async-logger-log
Enqueue a record into the async logger with an explicit level and message. This is the core write API behind all async level-specific convenience methods.
Enqueue a record into the async logger with an explicit level and message. This is the core write API behind all async level-specific convenience methods and the only built-in async write API that accepts a per-call target override.
### Interface
@@ -44,6 +44,7 @@ pub async fn[S] AsyncLogger::log(
Detailed rules explaining key parameters and behaviors
- The logger checks `is_enabled(level)` before building a record.
- If `target` is empty, the logger uses its stored default target. If `target` is non-empty, that value overrides the stored target for this call only.
- Context fields, patch logic, and filter logic are applied before enqueue.
- If timestamping is enabled, `@env.now()` is captured before the record enters the queue.
- Overflow behavior depends on the configured `AsyncOverflowPolicy`.
@@ -65,7 +66,16 @@ logger.log(
)
```
In this example, all per-record inputs are supplied explicitly.
In this example, the record overrides the logger's stored target only for this call.
#### When Reuse The Stored Async Target
When a call should keep the logger's existing target:
```moonbit
logger.log(@bitlogger.Level::Warn, "slow request")
```
In this example, the logger falls back to its stored target because no `target=` override is provided.
#### When Build Higher-level Async Logging Helpers
@@ -89,4 +99,4 @@ e.g.:
1. Use this API when the call site needs full control instead of a fixed severity helper.
2. Prefer `info()`, `warn()`, and the other shortcuts when only the level differs.
2. Prefer `info()`, `warn()`, and the other shortcuts when only the level differs and no per-call target override is needed.