birch/formatter
Log formatting utilities.
Formatters transform LogRecords into strings for output.
Types
A formatter is a function that converts a LogRecord to a string.
pub type Formatter =
fn(record.LogRecord) -> String
Values
pub fn format_metadata(
metadata: List(#(String, String)),
) -> String
Format metadata as key=value pairs separated by spaces.
pub fn format_metadata_colored(
metadata: List(#(String, String)),
use_color: Bool,
) -> String
Format metadata with color support. Each key gets a unique hash-based color when use_color is True.
pub fn format_metadata_visible(
metadata: List(#(String, String)),
) -> String
Format metadata, excluding internal keys (prefixed with _). Internal keys are used by the logging system for features like semantic log styles and grouping, and should not be shown to users.
pub fn format_metadata_with_bold(
metadata: List(#(String, String)),
highlight_keys: List(String),
use_color: Bool,
) -> String
Format metadata with specific keys highlighted. All keys get a unique hash-based color. Keys in the highlight_keys list are additionally styled with bold for extra visual distinction.
pub fn human_readable(record: record.LogRecord) -> String
Format a log record in a human-readable format.
Output format:
2024-12-26T10:30:45.123Z | INFO | myapp.http | Request complete | key=value
pub fn pad_level(level_str: String) -> String
Pad a level string to 5 characters for alignment. Uses pattern matching on known log level strings for efficiency.
pub fn simple(record: record.LogRecord) -> String
Format a log record as a simple message with level prefix.
Output format:
[INFO] Request complete