-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Problem
The default_logger() function reads the global config and constructs a new Logger value on every call to birch.info, birch.error, etc.:
fn default_logger() -> Logger {
let cfg = get_config()
logger.new("app")
|> logger.with_level(cfg.level)
|> logger.with_handlers(cfg.handlers)
|> logger.with_context(cfg.context)
}This means every log statement allocates a new Logger, reads from persistent storage, and chains multiple builder calls — even if the config hasn't changed.
Impact
For applications with sparse logging (like CLIs), this is negligible. But for hot paths or high-throughput services, this per-call overhead adds up unnecessarily.
Proposal
Cache the default logger and invalidate it only when birch.configure() is called:
- Store the built logger alongside the config in global state
- On
configure(), rebuild and cache the logger - On
default_logger(), return the cached logger directly
This is a pure internal optimization — no API changes needed.
Alternatives
- Use a generation counter: bump on
configure(), rebuild logger only when the counter changes - Accept the current behavior and document it as a tradeoff of the convenience API (users needing performance should use named loggers directly)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request