{"record":{"id":"c8658e63f19951d2","repo":"shadowsocks/shadowsocks-rust","slug":"logging","errorCode":null,"errorMessage":"logging","messagePattern":"logging","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/logging/log4rs.rs","lineNumber":67,"sourceCode":"\n    let (l1, l2) = match debug_level {\n        0 => (LevelFilter::Info, LevelFilter::Off),\n        1 => (LevelFilter::Debug, LevelFilter::Off),\n        2 => (LevelFilter::Trace, LevelFilter::Off),\n        3 => (LevelFilter::Trace, LevelFilter::Debug),\n        _ => (LevelFilter::Off, LevelFilter::Trace),\n    };\n\n    let config = match debug_level {\n        0..=3 => logging_builder\n            .logger(Logger::builder().build(bin_name, l1))\n            .logger(Logger::builder().build(\"shadowsocks_rust\", l1))\n            .logger(Logger::builder().build(\"shadowsocks\", l1))\n            .logger(Logger::builder().build(\"shadowsocks_service\", l1)),\n        _ => logging_builder,\n    }\n    .build(Root::builder().appender(\"console\").build(l2))\n    .expect(\"logging\");\n\n    log4rs::init_config(config).expect(\"logging\");\n}\n","sourceCodeStart":49,"sourceCodeEnd":71,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/src/logging/log4rs.rs#L49-L71","documentation":"Panic while building the log4rs Config object in init_with_config: the builder chain .build(...) returned Err (e.g. duplicate logger names or an invalid appender/logger setup) and expect('logging') panics. This is the first of the two expect calls, on config construction rather than initialization.","triggerScenarios":"init_with_config constructs a Config with appenders/loggers whose names collide or are invalid, causing ConfigBuilder::build to error before log4rs::init_config is reached.","commonSituations":"Bin-name-derived logger names duplicating the root/other loggers; programmatic LogConfig values producing zero or conflicting appenders; refactors changing logger name strings (shadowsocks_rust, shadowsocks, shadowsocks_service) into collisions.","solutions":["Ensure the programmatically built Config has unique logger and appender names","Print/log the generated config on failure instead of a bare expect","Validate the LogConfig inputs (level, format) before building the log4rs config","Check shadowsocks-rust updates for changes in init_with_config's builder logic"],"exampleFix":"// before\n.build(Root::builder().appender(\"console\").build(l2))\n.expect(\"logging\");\n// after\n.build(Root::builder().appender(\"console\").build(l2))\n.unwrap_or_else(|e| {\n    eprintln!(\"invalid logging config: {}\", e);\n    std::process::exit(1);\n})","handlingStrategy":"fallback","validationCode":"// ensure logger/appender names passed into the builder are unique before building\nassert_unique(&[\"shadowsocks_rust\", \"shadowsocks\", \"shadowsocks_service\"]);","typeGuard":null,"tryCatchPattern":"// build() returns Result and init_with_config expects it; wrap init in a fallible helper\nlet config = builder.build(root).map_err(|e| LoggingInitError(e))?;","preventionTips":["Keep logger names distinct from the root appender configuration","Log the generated config contents when debugging logging init","Initialize logging once, early in main, before spawning threads","Test init_with_config with each supported log level/format combination"],"tags":["rust","logging","log4rs","config","panic"],"backgroundTag":"invalid-config-value","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}