rlg-wasm 0.0.11

WebAssembly bindings for rlg. Bring structured logging into browsers, Deno, Cloudflare Workers, Bun, and any wasm-bindgen-capable host. Records are rendered in any of the 14 rlg LogFormats and dispatched to the host's console API.
Documentation

WASI 0.2 component (scaffold)

A component-model interface definition ships at wit/rlg.wit — package rlg:core@0.0.11, world rlg-logger. Consumable by any WASI 0.2 host (wasmtime run --component, jco, Fermyon Spin, …) once Phase 22.1 wires the wit-bindgen codegen. See docs/adr/0013-wasi-0.2-component.md.

Install

[dependencies]
rlg-wasm = "0.0.11"

Requires Rust 1.88.0 or newer (edition 2024). For the wasm32 target, install wasm-pack as shown below.

Build a WASM bundle

cargo install wasm-pack
wasm-pack build crates/rlg-wasm --target web --release

The pkg/ output contains the JS shims, TypeScript types, and the .wasm artifact.

Browser / Deno / Bun usage

import init, { RlgWasm } from "./pkg/rlg_wasm.js";

await init();

const rlg = new RlgWasm("worker", "JSON");
rlg.info("worker booted", JSON.stringify({ region: "eu-west-1" }));
rlg.warn("rate limited", null);
rlg.error("db timeout", JSON.stringify({ db: "primary", elapsed_ms: 5012 }));

Records render in the chosen LogFormat and dispatch to the host's console.log / console.warn / console.error based on the level.

Cloudflare Workers

# wrangler.toml
name = "my-worker"
main = "src/index.js"
compatibility_date = "2026-05-30"

[build]
command = "wasm-pack build --target web"
// src/index.js
import init, { RlgWasm } from "../pkg/rlg_wasm.js";
import wasm from "../pkg/rlg_wasm_bg.wasm";

let rlg;

export default {
    async fetch(request, env, ctx) {
        if (!rlg) {
            await init(wasm);
            rlg = new RlgWasm("my-worker", "JSON");
        }
        rlg.info("request received", JSON.stringify({
            url: request.url,
            method: request.method,
        }));
        return new Response("ok");
    },
};

Supported formats

All 14 LogFormat variants: CLF, CEF, ELF, W3C, ApacheAccessLog, Log4jXML, JSON, GELF, Logstash, NDJSON, MCP, OTLP, Logfmt, ECS. Pass the variant name as the second constructor argument.

License

Dual-licensed under Apache 2.0 or MIT, at your option.