{"record":{"id":"f52f854fca08fc77","repo":"nautechsystems/nautilus_trader","slug":"logging-has-been-shut-down-and-cannot-be-re-initia","errorCode":null,"errorMessage":"Logging has been shut down and cannot be re-initialized","messagePattern":"Logging has been shut down and cannot be re-initialized","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/logging/logger.rs","lineNumber":927,"sourceCode":"    )]\n    pub fn init_with_config(\n        trader_id: TraderId,\n        instance_id: UUID4,\n        config: LoggerConfig,\n        file_config: FileWriterConfig,\n    ) -> anyhow::Result<LogGuard> {\n        let mut lifecycle = LOGGER_LIFECYCLE.lock();\n\n        match *lifecycle {\n            LoggerLifecycle::Running => {\n                return LogGuard::new_locked().ok_or_else(|| {\n                    anyhow::anyhow!(\n                        \"Logging already initialized but new guard could not be created\"\n                    )\n                });\n            }\n            LoggerLifecycle::Terminated => {\n                anyhow::bail!(\"Logging has been shut down and cannot be re-initialized\");\n            }\n            LoggerLifecycle::Uninitialized => {}\n        }\n\n        let (tx, rx) = std::sync::mpsc::channel::<LogEvent>();\n        let filter_policy = FilterPolicy::from_config(&config);\n\n        #[cfg(not(all(feature = \"simulation\", madsim)))]\n        let handle = std::thread::Builder::new()\n            .name(LOGGING.to_string())\n            .spawn({\n                let config = config.clone();\n                let file_config = file_config.clone();\n                move || {\n                    Self::handle_messages(\n                        trader_id.to_string(),\n                        instance_id.to_string(),\n                        config,","sourceCodeStart":909,"sourceCodeEnd":945,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/logging/logger.rs#L909-L945","documentation":"The global logger tracks its lifecycle (Uninitialized, Running, Terminated). Once logging has been explicitly shut down (Terminated), calling init again is refused with this error because re-initialization after teardown is not supported. The logger must remain in its terminated state for the process lifetime after shutdown.","triggerScenarios":"Calling the logging init function (e.g. logger::init / logging initialization entry point) after a previous init was shut down via the logger's shutdown/flush-and-terminate path.","commonSituations":"Test harnesses that initialize logging per test after a global shutdown ran, application code that stops and restarts logging on config reload, or embedded usage where logging is torn down between sessions.","solutions":["Restructure the application to initialize logging exactly once, at startup, and never call shutdown until process exit.","If shutdown was called in a test, run it in a separate process or use a test harness that does not share the global logger.","Check that no early-exit/error path calls shutdown before the intended re-init.","If reconfiguration is needed, rebuild the config and re-init only while lifecycle is Uninitialized/Running per the API, not after Terminated."],"exampleFix":"// before\nlogging_shutdown();\nlogging_init(new_config)?; // bails: Terminated\n// after\nlogging_init(new_config)?; // init once at startup\n// ... run ...\nlogging_shutdown(); // only at process exit","handlingStrategy":"try-catch","validationCode":"fn can_init_logging(shutdown_called: std::cell::Cell<bool>) -> bool { !shutdown_called.get() }","typeGuard":null,"tryCatchPattern":"match logging_init(cfg) {\n    Err(e) if e.to_string().contains(\"shut down and cannot be re-initialized\") => {\n        // logging permanently stopped; proceed without logging or fail fast\n        eprintln!(\"logging unavailable: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Initialize logging once at process start via std::sync::Once.","Never call shutdown except in the final exit path.","In tests, avoid global shutdown or isolate per-process."],"tags":["logging","lifecycle","global-state","rust"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}