birch/config
Global configuration for the logging system.
This module provides types and functions for configuring the default logger and application-wide logging settings.
Types
Configuration options used in the builder pattern.
pub opaque type ConfigOption
Global configuration that affects the default logger and application-wide settings.
pub type GlobalConfig {
GlobalConfig(
level: level.Level,
handlers: List(handler.Handler),
context: List(#(String, String)),
on_error: option.Option(fn(handler.HandlerError) -> Nil),
sampling: Result(SampleConfig, Nil),
)
}
Constructors
-
GlobalConfig( level: level.Level, handlers: List(handler.Handler), context: List(#(String, String)), on_error: option.Option(fn(handler.HandlerError) -> Nil), sampling: Result(SampleConfig, Nil), )Arguments
- level
-
Minimum log level for the default logger
- handlers
-
Handlers to use for the default logger
- context
-
Default context metadata applied to all loggers
- on_error
-
Optional global error callback for handler failures
- sampling
-
Optional sampling configuration
Configuration for probabilistic sampling.
Logs at or below the configured level will be sampled at the specified rate. Logs above the configured level are always logged (no sampling applied).
pub type SampleConfig {
SampleConfig(level: level.Level, rate: Float)
}
Constructors
-
SampleConfig(level: level.Level, rate: Float)Arguments
- level
-
Apply sampling to this level and below
- rate
-
Probability of logging (0.0 to 1.0)
Values
pub fn apply_options(
config: GlobalConfig,
options: List(ConfigOption),
) -> GlobalConfig
Apply a list of configuration options to a GlobalConfig.
pub fn clear_global_config() -> Nil
Clear the global configuration from platform-specific storage.
pub fn context(ctx: List(#(String, String))) -> ConfigOption
Create a configuration option to set the default context.
pub fn empty() -> GlobalConfig
Returns the default global configuration with no handlers. Note: Use birch.default_config() to get defaults with console handler.
pub fn get_global_config() -> Result(GlobalConfig, Nil)
Get the global configuration from platform-specific storage. Returns Ok(config) if set, Error(Nil) if not configured.
pub fn get_level(config: GlobalConfig) -> level.Level
Get the log level from a GlobalConfig.
pub fn get_on_error(
config: GlobalConfig,
) -> option.Option(fn(handler.HandlerError) -> Nil)
Get the error callback from a GlobalConfig, if set.
pub fn handlers(h: List(handler.Handler)) -> ConfigOption
Create a configuration option to set the handlers.
pub fn level(lvl: level.Level) -> ConfigOption
Create a configuration option to set the log level.
pub fn on_error(
callback: fn(handler.HandlerError) -> Nil,
) -> ConfigOption
Create a configuration option to set the global error callback.
This callback is invoked when any handler encounters an error. It’s useful for monitoring and alerting on handler failures.
pub fn sampling(config: SampleConfig) -> ConfigOption
Create a configuration option to set sampling.
pub fn set_global_config(config: GlobalConfig) -> Nil
Set the global configuration in platform-specific storage.
pub fn with_level(
config: GlobalConfig,
lvl: level.Level,
) -> GlobalConfig
Update only the log level in a GlobalConfig, preserving other settings.