{"record":{"id":"0c9d730470af41b7","repo":"sigoden/dufs","slug":"failed-to-init-logger-e","errorCode":null,"errorMessage":"Failed to init logger, {e}","messagePattern":"Failed to init logger, (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":49,"sourceCode":"    Arc,\n};\nuse std::time::Duration;\nuse tokio::time::timeout;\nuse tokio::{net::TcpListener, task::JoinHandle};\n#[cfg(feature = \"tls\")]\nuse tokio_rustls::{rustls::ServerConfig, TlsAcceptor};\n\n#[tokio::main]\nasync fn main() -> Result<()> {\n    let cmd = build_cli();\n    let matches = cmd.get_matches();\n    if let Some(generator) = matches.get_one::<Shell>(\"completions\") {\n        let mut cmd = build_cli();\n        print_completions(*generator, &mut cmd);\n        return Ok(());\n    }\n    let mut args = Args::parse(matches)?;\n    logger::init(args.log_file.clone()).map_err(|e| anyhow!(\"Failed to init logger, {e}\"))?;\n    let (new_addrs, print_addrs) = check_addrs(&args)?;\n    args.addrs = new_addrs;\n    let running = Arc::new(AtomicBool::new(true));\n    let listening = print_listening(&args, &print_addrs)?;\n    let handles = serve(args, running.clone())?;\n    println!(\"{listening}\");\n\n    tokio::select! {\n        ret = join_all(handles) => {\n            for r in ret {\n                if let Err(e) = r {\n                    error!(\"{e}\");\n                }\n            }\n            Ok(())\n        },\n        _ = shutdown_signal() => {\n            running.store(false, Ordering::SeqCst);","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/sigoden/dufs/blob/fe7fd564f80dfbac361c8e0589c3845638149d38/src/main.rs#L31-L67","documentation":"`main` initializes the global logger (optionally writing to a log file) via `logger::init`. Any underlying error — e.g. the log file cannot be created or opened — is wrapped with anyhow into 'Failed to init logger, {e}' and aborts startup before the server binds.","triggerScenarios":"`--log-file` points to an unwritable path (missing directory, no permissions, path is a directory), or the logger backend fails to install.","commonSituations":"Running in a read-only container/filesystem; log directory not created before start; running as a non-root user pointing at /var/log; typo'd log path.","solutions":["Ensure the log file's parent directory exists and is writable by the process user.","Remove or correct the `--log-file` argument to log to the default destination.","Check filesystem permissions / read-only mounts (e.g. container volumes).","Create the directory first: `mkdir -p $(dirname $LOGFILE)` before starting."],"exampleFix":"// before\nduf --log-file /var/log/duf.log   (permission denied)\n// after\nmkdir -p /var/log && duf --log-file /var/log/duf.log  or use a writable path like ./duf.log","handlingStrategy":"try-catch","validationCode":"// before launch\nLOGFILE=./duf.log; mkdir -p \"$(dirname \"$LOGFILE\")\" && touch \"$LOGFILE\" || { echo \"log path unwritable\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match logger::init(path) { Ok(_) => {}, Err(e) => eprintln!(\"continuing without log file: {}\", e) }","preventionTips":["Create the log directory in deployment scripts","Run the server as a user with write access to the log path","Avoid log paths on read-only mounts","Smoke-test the full startup command in CI"],"tags":["rust","logging","startup","file-io"],"backgroundTag":"file-open-failed","analyzedSha":"fe7fd564f80dfbac361c8e0589c3845638149d38","analyzedAt":"2026-09-09T13:01:22.843Z","contentChangedAt":"2026-09-09T13:01:22.843Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}