{"record":{"id":"dda28577543129c4","repo":"risingwavelabs/risingwave","slug":"failed-to-create-directory-for-query-log","errorCode":null,"errorMessage":"failed to create directory '{}' for query log: {}","messagePattern":"failed to create directory '(.+?)' for query log: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/utils/runtime/src/logger.rs","lineNumber":365,"sourceCode":"                } else {\n                    fmt_layer.boxed()\n                }\n            }\n        };\n\n        layers.push(\n            fmt_layer\n                .with_filter(default_filter.clone().with_target(\"rw_tracing\", Level::OFF)) // filter-out tracing-only events\n                .boxed(),\n        );\n    };\n\n    // If `RW_QUERY_LOG_PATH` env var is set to a directory, turn on query log files.\n    let query_log_path = std::env::var(\"RW_QUERY_LOG_PATH\");\n    if let Ok(query_log_path) = query_log_path {\n        let query_log_path = PathBuf::from(query_log_path);\n        std::fs::create_dir_all(query_log_path.clone()).unwrap_or_else(|e| {\n            panic!(\n                \"failed to create directory '{}' for query log: {}\",\n                query_log_path.display(),\n                e.as_report(),\n            )\n        });\n\n        /// Newtype wrapper for `DefaultFields`.\n        ///\n        /// `fmt::Layer` will share the same `FormattedFields` extension for spans across\n        /// different layers, as long as the type of `N: FormatFields` is the same. This\n        /// will cause several problems:\n        ///\n        /// - `with_ansi(false)` does not take effect and it will follow the settings of\n        ///   the primary fmt layer installed above.\n        /// - `Span::record` will update the same `FormattedFields` multiple times,\n        ///   leading to duplicated fields.\n        ///\n        /// As a workaround, we use a newtype wrapper here to get a different type id.","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/utils/runtime/src/logger.rs#L347-L383","documentation":"When `RW_QUERY_LOG_PATH` is set, init_risingwave_logger calls `std::fs::create_dir_all` on it and panics on failure with the path and OS error. This enables per-query log files, so the directory must be creatable before logging is wired up.","triggerScenarios":"RW_QUERY_LOG_PATH points somewhere create_dir_all cannot create: permission-denied, a parent component is a file, read-only filesystem, or invalid path characters.","commonSituations":"Pointing at a root-owned or non-writable volume in containers; path collides with an existing file; mounting a read-only volume at that path; typo making an impossible deep path.","solutions":["Create/fix the directory permissions first (mkdir -p <path>; chown the running user).","Point RW_QUERY_LOG_PATH at a writable volume (e.g. /var/log/risingwave/query).","If an existing file occupies the path, remove or rename it.","Unset RW_QUERY_LOG_PATH to disable query logging entirely."],"exampleFix":"// before: read-only path\nRW_QUERY_LOG_PATH=/mnt/readonly/querylog\n// after: writable volume\nRW_QUERY_LOG_PATH=/var/log/risingwave/query","handlingStrategy":"validation","validationCode":"use std::path::Path;\nlet p = std::env::var(\"RW_QUERY_LOG_PATH\").unwrap_or_default();\nlet path = Path::new(&p);\nif !p.is_empty() && (path.exists() && !path.is_dir()) {\n    panic!(\"RW_QUERY_LOG_PATH is not a directory: {p}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-provision and chown the log directory in your container image or entrypoint.","Mount a writable volume at the configured path.","Verify the path is a directory, not an existing file, before startup."],"tags":["rust","logging","filesystem","mkdir","env-var"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}