viva_telemetry/log/handler
Handler interface for log outputs
Handlers receive log entries and output them somewhere:
- Console (stdout/stderr)
- File (with rotation)
- JSON file (structured)
- Custom (network, database, etc.)
Types
Console handler configuration
pub type ConsoleConfig {
ConsoleConfig(
level: level.Level,
colored: Bool,
stderr_for_errors: Bool,
)
}
Constructors
-
ConsoleConfig( level: level.Level, colored: Bool, stderr_for_errors: Bool, )Arguments
- level
-
Minimum level to log
- colored
-
Use ANSI colors
- stderr_for_errors
-
Output to stderr for errors (else stdout)
Custom handler configuration
pub type CustomConfig {
CustomConfig(
level: level.Level,
handler_fn: fn(entry.Entry) -> Nil,
)
}
Constructors
-
CustomConfig( level: level.Level, handler_fn: fn(entry.Entry) -> Nil, )Arguments
- level
-
Minimum level to log
- handler_fn
-
Custom handler function
File handler configuration
pub type FileConfig {
FileConfig(
level: level.Level,
path: String,
rotation: Rotation,
)
}
Constructors
-
FileConfig(level: level.Level, path: String, rotation: Rotation)Arguments
- level
-
Minimum level to log
- path
-
File path
- rotation
-
Rotation strategy
Handler configuration
pub type Handler {
ConsoleHandler(config: ConsoleConfig)
JsonHandler(config: JsonConfig)
FileHandler(config: FileConfig)
CustomHandler(config: CustomConfig)
}
Constructors
-
ConsoleHandler(config: ConsoleConfig)Console handler - outputs to stdout/stderr
-
JsonHandler(config: JsonConfig)JSON handler - outputs structured JSON to file
-
FileHandler(config: FileConfig)File handler - outputs plain text to file
-
CustomHandler(config: CustomConfig)Custom handler - user-provided function
JSON handler configuration
pub type JsonConfig {
JsonConfig(level: level.Level, path: String, pretty: Bool)
}
Constructors
-
JsonConfig(level: level.Level, path: String, pretty: Bool)Arguments
- level
-
Minimum level to log
- path
-
File path
- pretty
-
Pretty print JSON
Values
pub fn console_with_level(lvl: level.Level) -> Handler
Console handler with custom level
pub fn custom(
lvl: level.Level,
handler_fn: fn(entry.Entry) -> Nil,
) -> Handler
Custom handler
pub fn file_with_rotation(
path: String,
rotation: Rotation,
) -> Handler
File handler with rotation
pub fn json_with_level(path: String, lvl: level.Level) -> Handler
JSON handler with level
pub fn should_log(
handler: Handler,
log_level: level.Level,
) -> Bool
Check if handler should process this level