mirror of
https://github.com/Nanaloveyuki/BitLogger.git
synced 2026-05-30 23:52:27 +00:00
✨ Add template-based text formatter
This commit is contained in:
+8
-3
@@ -22,7 +22,7 @@ BitLogger currently provides:
|
||||
- patch helpers such as `prefix_message(...)`, `append_fields(...)`, and `redact_fields(...)`
|
||||
- explicit queued delivery via `queued_sink(...)` and `with_queue(...)`
|
||||
- bounded backlog with `QueueOverflowPolicy::DropNewest` and `QueueOverflowPolicy::DropOldest`
|
||||
- configurable text formatting via `text_formatter(...)`, `format_text(...)`, and `text_console_sink(...)`
|
||||
- configurable text formatting via `text_formatter(...)`, `format_text(...)`, `text_console_sink(...)`, and template-driven `template` output
|
||||
- formatter-based callback integration via `formatted_callback_sink(...)`
|
||||
- native-only file output via `file_sink(...)`
|
||||
- `native_files_supported()` for backend capability detection
|
||||
@@ -124,7 +124,11 @@ ignore(logger.sink.flush())
|
||||
Custom text formatter:
|
||||
|
||||
```moonbit
|
||||
let formatter = text_formatter(show_timestamp=false, separator=" | ")
|
||||
let formatter = text_formatter(
|
||||
show_timestamp=false,
|
||||
field_separator=",",
|
||||
template="[{level}] {target} {message} :: {fields}",
|
||||
)
|
||||
let logger = Logger::new(text_console_sink(formatter), target="pretty")
|
||||
|
||||
logger.info("hello", fields=[field("mode", "pretty")])
|
||||
@@ -134,7 +138,7 @@ JSON config loading:
|
||||
|
||||
```moonbit
|
||||
let config = parse_logger_config_text(
|
||||
"{\"min_level\":\"debug\",\"target\":\"config.demo\",\"timestamp\":true,\"sink\":{\"kind\":\"text_console\",\"text_formatter\":{\"separator\":\" | \",\"show_timestamp\":false}},\"queue\":{\"max_pending\":2,\"overflow\":\"DropOldest\"}}",
|
||||
"{\"min_level\":\"debug\",\"target\":\"config.demo\",\"timestamp\":true,\"sink\":{\"kind\":\"text_console\",\"text_formatter\":{\"show_timestamp\":false,\"field_separator\":\",\",\"template\":\"[{level}] {target} {message} :: {fields}\"}},\"queue\":{\"max_pending\":2,\"overflow\":\"DropOldest\"}}",
|
||||
)
|
||||
|
||||
let logger = build_logger(config)
|
||||
@@ -168,6 +172,7 @@ if native_files_supported() {
|
||||
|
||||
- BitLogger now includes a JSON config layer via `parse_logger_config_text(...)`, `stringify_logger_config(...)`, and `build_logger(...)`.
|
||||
- Supported keys include `min_level`, `target`, `timestamp`, `sink.kind`, `sink.path`, `sink.append`, `sink.auto_flush`, `sink.text_formatter`, and `queue`.
|
||||
- `sink.text_formatter.template` currently supports fixed tokens: `{timestamp}`, `{timestamp_ms}`, `{level}`, `{target}`, `{message}`, and `{fields}`.
|
||||
- Config-driven sink assembly currently supports `console`, `json_console`, `text_console`, and `file`.
|
||||
- `queue` remains a synchronous bounded wrapper around the final sink, not an async runtime.
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ version 0.3.0
|
||||
- feat: support config keys `min_level`, `target`, `timestamp`, `sink.kind`, `sink.path`, `sink.append`, `sink.auto_flush`, `sink.text_formatter`, and `queue`
|
||||
- feat: support config-driven sink assembly for `console`, `json_console`, `text_console`, and `file`
|
||||
- feat: use `maria/json_parser` as the first external dependency for practical config loading
|
||||
- feat: add `TextFormatter.template` and `TextFormatterConfig.template` for template-driven text rendering
|
||||
- feat: support formatter tokens `{timestamp}`, `{timestamp_ms}`, `{level}`, `{target}`, `{message}`, and `{fields}` in both runtime and JSON config paths
|
||||
|
||||
### Test
|
||||
|
||||
@@ -34,6 +36,7 @@ version 0.3.0
|
||||
- test: cover config-built queued text logger flushing and pending count behavior
|
||||
- test: cover partial drain behavior for config-built queued logger
|
||||
- test: cover dropped-count reporting for bounded config-built queue
|
||||
- test: cover template-based formatter rendering and disabled token behavior
|
||||
- test: add async logger lifecycle, config roundtrip, and batching/flush policy test seeds
|
||||
- build: verify `bitlogger_async --target native` and `examples/async_basic --target native` compile successfully
|
||||
|
||||
@@ -44,11 +47,13 @@ version 0.3.0
|
||||
- docs: add `examples/async_basic` to show async worker startup and queue-backed logging flow
|
||||
- docs: update `examples/async_basic` to use unified JSON-driven async logger config
|
||||
- docs: update root README, English README, and Mooncake README with config usage notes
|
||||
- docs: update formatter examples to demonstrate template-based text rendering
|
||||
- docs: update root README and English README with async adapter notes and current scope
|
||||
- chore: ignore local `.mooncakes/` cache directory in git
|
||||
|
||||
### Notes
|
||||
|
||||
- current config scope is still intentionally constrained to stable built-in sink shapes
|
||||
- formatter templates are intentionally limited to simple token replacement and do not yet include conditional blocks or alignment/padding controls
|
||||
- queue wrapping remains synchronous drain-based delivery, not async runtime scheduling
|
||||
- async logging remains an isolated adapter layer and currently targets `native/llvm` only
|
||||
|
||||
Reference in New Issue
Block a user