Files
BitLogger/docs/api/logger-info.md
T
2026-05-12 16:06:00 +08:00

78 lines
2.1 KiB
Markdown

---
name: logger-info
group: api
category: logging
update-time: 20260512
description: Emit an info-level record through the logger using the standard informational severity shortcut.
key-word:
- logger
- info
- sync
- public
---
## Logger-info
Emit an info-level record through the synchronous logger. This is the convenience wrapper for `log(Level::Info, ...)`.
### Interface
```moonbit
pub fn[S : Sink] Logger::info(self : Logger[S], message : String, fields~ : Array[Field] = []) -> Unit {}
```
#### input
- `self : Logger[S]` - Logger that should emit the info record.
- `message : String` - Informational message text.
- `fields : Array[Field]` - Optional structured fields attached to the record.
#### output
- `Unit` - No return value. The record is handled according to the logger threshold and sink pipeline.
### Explanation
Detailed rules explaining key parameters and behaviors
- This helper delegates to `log(Level::Info, ...)`.
- `Info` is the default minimum logger threshold unless changed explicitly.
- Per-call target override is not exposed here; use `log(...)` if needed.
- Context fields, filters, patches, and queue wrappers behave exactly as they do for other write methods.
### How to Use
Here are some specific examples provided.
#### When Emit Normal Application Events
When a service should report standard lifecycle milestones:
```moonbit
logger.info("service started")
```
In this example, the log event uses the normal informational severity.
#### When Attach Structured Informational Context
When an info event should include machine-readable metadata:
```moonbit
logger.info("request completed", fields=[field("status", "200")])
```
In this example, the event remains concise while still carrying useful fields.
### Error Case
e.g.:
- If the logger minimum level is above `Info`, the call returns without writing a record.
- If the event needs an explicit alternate target, use `log(...)` instead of this shortcut.
### Notes
1. This is the most common convenience method for normal application events.
2. Because `Info` is often the default threshold, this helper is a common baseline for examples and docs.