Having trouble on creating Layers under tracing

⚓ rust    📅 2025-05-29    👤 surdeus    👁️ 3      

surdeus

Warning

This post was published 31 days ago. The information described in this article may have changed.

I have the following code

        // configs is just a struct maintaining the logger / layer's settings
        for config in loggers.configs.iter() {
            match config.logger_type.as_str() {
                // stdout will create a layer to log at std-out simply
                "stdout" => {
                    // the fn returns a Result<Layer<Registry>, std::io::Error>; hence I simply unwrap it
                    let layer = setup_stdout_logger().unwrap();
                    // * this failed as 
                    // `subscriber` moved due to this method call, in previous iteration of loop
                    subscriber.with(layer); 
                }
                "file" => {
                    let layer = setup_file_logger().unwrap();
                    // * this doesn't work either as the return data type after with() is 
                    // different (should say incremental)
                    subscriber = subscriber.with(layer).boxed();
                }
                _ => {}
            }
        }

so I could not find a solution on this; need some help

  • issue 1 : subscriber.with(xxx) won't work as moved
  • issue 2 : re-assignment not work as well since the original subscriber is of another type (Registry) but after calling with() returning Layer<x, y> instead

if not within a loop; this somehow works as expected

let subscriber = Registry::default().with(xxx).with(yyy);

2 posts - 2 participants

Read full topic

🏷️ rust_feed