{"id":50910514,"url":"https://github.com/quartiq/defmt2log","last_synced_at":"2026-06-16T09:33:12.002Z","repository":{"id":355707759,"uuid":"1229140737","full_name":"quartiq/defmt2log","owner":"quartiq","description":null,"archived":false,"fork":false,"pushed_at":"2026-06-02T09:31:48.000Z","size":53,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-02T11:18:56.676Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quartiq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-04T18:36:35.000Z","updated_at":"2026-06-02T09:31:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/quartiq/defmt2log","commit_stats":null,"previous_names":["quartiq/defmt2log"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/quartiq/defmt2log","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartiq%2Fdefmt2log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartiq%2Fdefmt2log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartiq%2Fdefmt2log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartiq%2Fdefmt2log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quartiq","download_url":"https://codeload.github.com/quartiq/defmt2log/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quartiq%2Fdefmt2log/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34400451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-16T09:33:11.926Z","updated_at":"2026-06-16T09:33:11.992Z","avatar_url":"https://github.com/quartiq.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `defmt2log`\n\nKeep writing real `defmt` in code that also runs on the host.\n\n`defmt2log` is a `defmt::Logger`/`#[global_logger]` that decodes\n`defmt` frames and emits ordinary [`log`](https://docs.rs/log) records,\nso you keep:\n\n- full `defmt` format hints and syntax in the code\n- `DEFMT_LOG` compile-time filtering\n- normal host `log` tooling such as `RUST_LOG`, `env_logger`, and downstream\n  `log` sinks\n\nOn Linux/ELF it can initialize without a special linker script in many cases:\n\n- `init_from_current_exe()` for the normal host-binary case\n- `init_from_merged_elf_path(path)` for any ELF path with a merged `.defmt`\n  section\n- `init_from_merged_elf_bytes(bytes)` for pre-merged ELF bytes\n\nAll initialization functions panic on failure.\n\n## Usage\n\n```rust\nenv_logger::init();\ndefmt2log::init_from_current_exe();\ndefmt::info!(\"word {=u32:#010x}\", 0x1234u32);\n```\n\n- normal debug and release host binaries work as well as libtest unit\n  tests, examples, and integration tests; they need one `defmt2log::init_from_*()`\n- rustdoc doctest executables are worse: the bundled doctest rlib still\n  contains `.defmt.info.*`, but the final `rust_out` test executable has\n  them stripped.\n\nRecommended default:\n\n- build with `DEFMT_LOG=info`\n- run with `RUST_LOG=info` (when using `env_logger`)\n- leave `log` compile-time max-level features alone\n- source locations are loaded on a best-effort basis; if they cannot be loaded,\n  decoding still works and `defmt2log` warns once\n- if `DEFMT_LOG` is unset or more restrictive than your callsites, normal\n  `defmt::{trace,debug,info,warn,error}!` output is compiled out entirely; in\n  that case `defmt2log` may still initialize successfully, but there is\n  nothing for it to decode\n- `DEFMT_LOG=off` and no `defmt::println!()` removes the need for a `defmt` `#[global_logger]`\n\n## Filters\n\n- `DEFMT_LOG` is the compile-time filter for `defmt`\n- `RUST_LOG` is the runtime filter for the host `env_logger` `log` sink\n- `max_level_*` and `release_max_level_*` affect ordinary host `log` callsites,\n  not `defmt`\n\nThe important consequence is simple: `RUST_LOG` cannot bring back `defmt`\ncallsites that `DEFMT_LOG` compiled out.\n\n`defmt::println!()` is decoded and printed directly to stdout, bypassing\n`RUST_LOG`, with best-effort source location metadata.\n\n## Avoid\n\n- `DEFMT_LOG=trace` with `RUST_LOG=warn` unless you intentionally want to pay\n  decode cost for logs the sink will hide\n- using `max_level_*` features to control `defmt`\n- using `init_from_merged_elf_bytes()` for a normal host executable; that API\n  is only for ELFs that already contain a merged `.defmt` section.\n- expecting `init_from_merged_elf_path(path)` to synthesize a table for an\n  arbitrary non-running host binary without a merged `.defmt` section\n\n## Limitations\n\n- doctests tend to not produce output:\n  the final doctest executable loses the split `.defmt.*` metadata even when\n  the doctest itself still compiles and passes\n- `defmt2log` is typically less efficient than pure `log`; the overhead is\n  the sum of the defmt overheads: encoding, decoding, and formatting\n- every compile-time-enabled `defmt` frame is decoded in-process\n- `init_from_current_exe()` is Linux-oriented today:\n  the split-`.defmt.*` current-executable path depends on loader-reported\n  mappings via `findshlibs`\n- `init_from_merged_elf_path()` and `init_from_merged_elf_bytes()` are the\n  more portable modes: they work when the input already has a merged `.defmt`\n  section\n- native macOS current-executable support is not a supported path today\n- host bitflags names require linker support that preserves `.defmt.end*`\n  metadata; without that, host decoders only see the bitflags format tag and\n  fall back to the raw numeric value\n- dynamically loaded objects are not gathered today; `init_from_current_exe()`\n  only decodes metadata from the main executable\n\n## Alternatives\n\n- only `log::*`: simplest host setup, but you give up efficient `defmt` format\n  hints and `DEFMT_LOG` compile-time filtering.\n- `defmt-or-log` or the `fmt.rs` trick: useful when one shared codebase must\n  compile against either backend, but the shared callsites have to stay within\n  the portable subset.\n- `defmt-logger`: also aims at `defmt` -\u003e `log` but it is old. `defmt2log` is built\n  around current `defmt-decoder` `log` interop and preserves the normal host\n  `log` pipeline end to end: `RUST_LOG` filtering, existing sinks, and other\n  downstream `log` machinery.\n- external decoding such as `defmt-print`: keeps full `defmt`, but moves the\n  decode and process orchestration outside the program. `defmt2log` keeps the\n  same logging stream inside the host process, merges with other `log` sources,\n  and feeds ordinary `log` sinks directly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquartiq%2Fdefmt2log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquartiq%2Fdefmt2log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquartiq%2Fdefmt2log/lists"}