BoundaryML/baml · critical · RuntimeError
Failed to initialize BAML logger: {e:#}
Error message
Failed to initialize BAML logger: {e:#} What it means
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.
Source
Thrown at engine/language_client_ruby/ext/ruby_ffi/src/lib.rs:325
baml_runtime::RuntimeCliDefaults {
output_type: baml_types::GeneratorOutputType::RubySorbet,
},
) {
Ok(exit_code) => Ok(exit_code.into()),
Err(e) => Err(Error::new(
ruby.exception_runtime_error(),
format!(
"{:?}",
e.context("error while invoking baml-cli".to_string())
),
)),
}
}
#[magnus::init(name = "ruby_ffi")]
fn init(ruby: &Ruby) -> Result<()> {
baml_log::init().map_err(|e| {
Error::new(
ruby.exception_runtime_error(),
format!("Failed to initialize BAML logger: {e:#}"),
)
})?;
let module = ruby.define_module("Baml")?.define_module("Ffi")?;
module.define_module_function("invoke_runtime_cli", function!(invoke_runtime_cli, 2))?;
// must be kept in sync with the magnus::wrap annotation
let runtime_class = module.define_class("BamlRuntime", class::object())?;
runtime_class.define_singleton_method(
"from_directory",
function!(BamlRuntimeFfi::from_directory, 2),
)?;
runtime_class
.define_singleton_method("from_files", function!(BamlRuntimeFfi::from_files, 3))?;
runtime_class.define_method(View on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before ENV["BAML_LOG"] = "verbose" require "baml" // after ENV["BAML_LOG"] = "debug" # valid level: trace|debug|info|warn|error require "baml"
Defensive patterns
Strategy: validation
Validate before calling
valid = %w[trace debug info warn error off]
if (lvl = ENV['BAML_LOG']) && !valid.include?(lvl.split(/[=,]/).first)
raise "invalid BAML_LOG level: #{lvl}"
end
require 'tmpdir'
raise 'no writable tmp dir' unless File.writable?(Dir.tmpdir) Try / catch
begin
require 'baml'
rescue RuntimeError => e
raise unless e.message.start_with?('Failed to initialize BAML logger')
ENV.delete('BAML_LOG')
require 'baml'
end Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Engine not initialized. Call create_baml_runtime first.
- Project not initialized
- panic(initErr)
- failed to get logs: %w
- No LLM response: {}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/d8493f9316abf5b4.
Report an issue: GitHub.