diff --git a/README.md b/README.md index 1d49f2c..ee49520 100644 --- a/README.md +++ b/README.md @@ -366,6 +366,7 @@ match logger.file_runtime_state() { - async worker 支持 `max_batch` 批量消费, 以及 `flush=Never|Batch|Shutdown` 的基础 flush 策略 - 提供 `async_runtime_mode()` / `async_runtime_mode_label(...)` / `async_runtime_supports_background_worker()` 用于探测当前后端是原生 worker 还是兼容实现 - 提供 `async_runtime_state_to_json(...)` / `stringify_async_runtime_state(...)`, 便于在启动日志或诊断输出里直接暴露当前 async runtime 模式 +- 提供 `AsyncLogger::state()` 与 `async_logger_state_to_json(...)` / `stringify_async_logger_state(...)`, 可输出完整的 async logger 运行时快照 - 示例见 [examples/async_basic/main.mbt](/E:/repo/MooLiteyukiBot/examples/async_basic/main.mbt:1) - `bitlogger_async` 现在支持多端编译: `native/llvm` 保留后台 worker 语义, `js` / `wasm` / `wasm-gc` 提供兼容实现 - 由于 `moonbitlang/async` 的 `async fn main` 入口当前仍有限制, `examples/async_basic` 示例仍保持 `native` target @@ -374,6 +375,7 @@ match logger.file_runtime_state() { ```moonbit println(stringify_async_runtime_state(async_runtime_state(), pretty=true)) +println(stringify_async_logger_state(logger.state(), pretty=true)) ``` ### Async Config diff --git a/docs/README-en.md b/docs/README-en.md index 9cd0884..21acb23 100644 --- a/docs/README-en.md +++ b/docs/README-en.md @@ -342,6 +342,7 @@ match logger.file_runtime_state() { - The async worker now supports batched queue draining via `max_batch` and basic flush policies through `flush=Never|Batch|Shutdown`. - `async_runtime_mode()`, `async_runtime_mode_label(...)`, and `async_runtime_supports_background_worker()` expose whether the current backend is using the native worker path or the compatibility implementation. - `async_runtime_state_to_json(...)` and `stringify_async_runtime_state(...)` make it easy to include the current async runtime mode in startup diagnostics or health output. +- `AsyncLogger::state()` together with `async_logger_state_to_json(...)` / `stringify_async_logger_state(...)` exposes a full async logger runtime snapshot for diagnostics. - The recommended startup pattern is shown in [examples/async_basic/main.mbt](/E:/repo/MooLiteyukiBot/examples/async_basic/main.mbt:1). - `bitlogger_async` now compiles across multiple targets: `native/llvm` keeps the background worker semantics, while `js` / `wasm` / `wasm-gc` use a compatibility implementation. - Because `moonbitlang/async` still limits `async fn main` entry support, the `examples/async_basic` executable remains `native`-only for now. @@ -350,6 +351,7 @@ Startup diagnostic example: ```moonbit println(stringify_async_runtime_state(async_runtime_state(), pretty=true)) +println(stringify_async_logger_state(logger.state(), pretty=true)) ``` ### Async Config diff --git a/examples/async_basic/main.mbt b/examples/async_basic/main.mbt index 257f9b4..7ad62a1 100644 --- a/examples/async_basic/main.mbt +++ b/examples/async_basic/main.mbt @@ -18,6 +18,8 @@ async fn main { @lib.redact_fields(["token"]), ])) + println(@lib_async.stringify_async_logger_state(logger.state(), pretty=true)) + @async.with_task_group(group => { group.spawn_bg(allow_failure=true, () => logger.run()) logger.info("one", fields=[@lib.field("token", "secret")]) @@ -26,4 +28,6 @@ async fn main { logger.with_target("skip.demo").info("three") logger.shutdown() }) + + println(@lib_async.stringify_async_logger_state(logger.state(), pretty=true)) }