{"record":{"id":"d8493f9316abf5b4","repo":"BoundaryML/baml","slug":"failed-to-initialize-baml-logger-e","errorCode":null,"errorMessage":"Failed to initialize BAML logger: {e:#}","messagePattern":"Failed to initialize BAML logger: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"engine/language_client_ruby/ext/ruby_ffi/src/lib.rs","lineNumber":325,"sourceCode":"        baml_runtime::RuntimeCliDefaults {\n            output_type: baml_types::GeneratorOutputType::RubySorbet,\n        },\n    ) {\n        Ok(exit_code) => Ok(exit_code.into()),\n        Err(e) => Err(Error::new(\n            ruby.exception_runtime_error(),\n            format!(\n                \"{:?}\",\n                e.context(\"error while invoking baml-cli\".to_string())\n            ),\n        )),\n    }\n}\n\n#[magnus::init(name = \"ruby_ffi\")]\nfn init(ruby: &Ruby) -> Result<()> {\n    baml_log::init().map_err(|e| {\n        Error::new(\n            ruby.exception_runtime_error(),\n            format!(\"Failed to initialize BAML logger: {e:#}\"),\n        )\n    })?;\n\n    let module = ruby.define_module(\"Baml\")?.define_module(\"Ffi\")?;\n\n    module.define_module_function(\"invoke_runtime_cli\", function!(invoke_runtime_cli, 2))?;\n\n    // must be kept in sync with the magnus::wrap annotation\n    let runtime_class = module.define_class(\"BamlRuntime\", class::object())?;\n    runtime_class.define_singleton_method(\n        \"from_directory\",\n        function!(BamlRuntimeFfi::from_directory, 2),\n    )?;\n    runtime_class\n        .define_singleton_method(\"from_files\", function!(BamlRuntimeFfi::from_files, 3))?;\n    runtime_class.define_method(","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_ruby/ext/ruby_ffi/src/lib.rs#L307-L343","documentation":"Raised by the magnus #[init] entry point of the ruby_ffi extension when baml_log::init() fails while loading the Baml native module. The extension aborts loading and surfaces a Ruby RuntimeError: 'Failed to initialize BAML logger: {e:#}'. Because it happens at require time, the entire Baml module is unavailable.","triggerScenarios":"Requiring 'baml' / the ruby_ffi native extension in an environment where the BAML logger cannot initialize: BAML_LOG env var set to an invalid level, unwritable log file path/directory, or a logger-internal initialization error.","commonSituations":"Deploying to a read-only filesystem or container where the default log location is not writable; setting BAML_LOG to a bogus filter string; conflicting log initialization when another native extension already set a global logger.","solutions":["Check the {e:#} detail in the message for the exact logger failure reason.","Verify the BAML_LOG / RUST_LOG env var, if set, is a valid log filter (e.g. 'info', 'debug', 'baml=debug').","Ensure the process can write to the log output location (writable HOME/TMPDIR in containers).","Unset BAML_LOG to fall back to defaults and retry requiring the gem.","Upgrade the baml gem; older versions had stricter logger init behavior."],"exampleFix":"// before\nENV[\"BAML_LOG\"] = \"verbose\"\nrequire \"baml\"\n\n// after\nENV[\"BAML_LOG\"] = \"debug\" # valid level: trace|debug|info|warn|error\nrequire \"baml\"","handlingStrategy":"validation","validationCode":"valid = %w[trace debug info warn error off]\nif (lvl = ENV['BAML_LOG']) && !valid.include?(lvl.split(/[=,]/).first)\n  raise \"invalid BAML_LOG level: #{lvl}\"\nend\nrequire 'tmpdir'\nraise 'no writable tmp dir' unless File.writable?(Dir.tmpdir)","typeGuard":null,"tryCatchPattern":"begin\n  require 'baml'\nrescue RuntimeError => e\n  raise unless e.message.start_with?('Failed to initialize BAML logger')\n  ENV.delete('BAML_LOG')\n  require 'baml'\nend","preventionTips":["Keep BAML_LOG set only to valid levels (trace|debug|info|warn|error).","Ensure containers have a writable TMPDIR/HOME for log output.","Test `require 'baml'` in a smoke test for each deployment image.","Avoid requiring baml before logger-related env vars are finalized."],"tags":["ruby","logging","initialization","ffi"],"backgroundTag":"module-init-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}