linera-io/linera-protocol · error

Invalid RUST_LOG_FORMAT: `{format}`. Valid values are `json

Error message

Invalid RUST_LOG_FORMAT: `{format}`.  Valid values are `json` or `pretty`.

What it means

prepare_formatted_layer selects the tracing output format from the RUST_LOG_FORMAT environment variable. Recognized values are 'json' and 'pretty' (plus wasm-specific handling); anything else falls into the catch-all arm and panics with a message listing the valid values. The function feeds stderr_layer and maybe_log_file_layer, so it runs during logging initialization in linera-service binaries.

Source

Thrown at linera-service/src/tracing/mod.rs:211

    N: for<'writer> FormatFields<'writer> + Send + Sync + 'static,
    W: for<'writer> MakeWriter<'writer> + Send + Sync + 'static,
    T: FormatTime + Send + Sync + 'static,
{
    match formatting.unwrap_or("plain") {
        "json" => layer.json().boxed(),
        "pretty" => layer.pretty().boxed(),
        "plain" => {
            #[cfg(not(target_arch = "wasm32"))]
            {
                layer.event_format(WithTraceContext).boxed()
            }
            #[cfg(target_arch = "wasm32")]
            {
                layer.boxed()
            }
        }
        format => {
            panic!("Invalid RUST_LOG_FORMAT: `{format}`.  Valid values are `json` or `pretty`.")
        }
    }
}

pub(crate) fn fmt_span_from_str(events: &str) -> FmtSpan {
    let mut fmt_span = FmtSpan::NONE;
    for event in events.split(',') {
        fmt_span |= match event {
            "new" => FmtSpan::NEW,
            "enter" => FmtSpan::ENTER,
            "exit" => FmtSpan::EXIT,
            "close" => FmtSpan::CLOSE,
            "active" => FmtSpan::ACTIVE,
            "full" => FmtSpan::FULL,
            _ => FmtSpan::NONE,
        };
    }
    fmt_span

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Set RUST_LOG_FORMAT=json or RUST_LOG_FORMAT=pretty exactly, or unset it to use the default
  2. Strip whitespace/casing issues in deployment env files
  3. Audit environment templates for copied-in logging variables from other frameworks

Example fix

# before
export RUST_LOG_FORMAT=text   # panics

# after
export RUST_LOG_FORMAT=pretty  # or: unset RUST_LOG_FORMAT
Defensive patterns

Strategy: validation

Validate before calling

fn valid_log_format(v: &str) -> bool { matches!(v.trim(), "json" | "pretty") }
if let Ok(format) = std::env::var("RUST_LOG_FORMAT") {
    assert!(valid_log_format(&format), "RUST_LOG_FORMAT must be json or pretty");
}

Prevention

When it happens

Trigger: Starting any linera-service binary (validator, proxy, node, faucet, indexer CLI tooling) with RUST_LOG_FORMAT set to something other than json/pretty — e.g. 'JSON', 'text', 'logfmt', 'plain', or a value with trailing whitespace/newline.

Common situations: CI pipelines or container env files exporting generic logging variables copied from other stacks (LOG_FORMAT=text); shell quoting mistakes; docker-compose env entries with stray spaces.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/0a7794f339b4957d. Report an issue: GitHub.