Skip to main content

custom_logger

Function custom_logger 

Source
pub fn custom_logger<D, I, W, E>(
    debug_fn: D,
    info_fn: I,
    warn_fn: W,
    error_fn: E,
) -> CustomLogger<D, I, W, E>
where D: Fn(&str, &LogInfo) + Send + Sync, I: Fn(&str, &LogInfo) + Send + Sync, W: Fn(&str, &LogInfo) + Send + Sync, E: Fn(&str, &LogInfo) + Send + Sync,
Expand description

Creates a custom logger with user-provided closures for each log level.

This factory function allows users to create custom logging behavior without implementing the sealed Logger trait directly. Each log level has its own closure that receives the log message and context information.

§Arguments

  • debug_fn - Closure called for debug-level messages
  • info_fn - Closure called for info-level messages
  • warn_fn - Closure called for warning-level messages
  • error_fn - Closure called for error-level messages

§Example

use durable_execution_sdk::context::{custom_logger, LogInfo};
use std::sync::Arc;

// Create a custom logger that prints to stdout
let logger = custom_logger(
    |msg, info| println!("[DEBUG] {}: {:?}", msg, info),
    |msg, info| println!("[INFO] {}: {:?}", msg, info),
    |msg, info| println!("[WARN] {}: {:?}", msg, info),
    |msg, info| println!("[ERROR] {}: {:?}", msg, info),
);

// Use with Arc for sharing across contexts
let shared_logger = Arc::new(logger);