Skip to main content

Crate tpt_logfmt_parse

Crate tpt_logfmt_parse 

Source
Expand description

§tpt-logfmt-parse

docs.rs crates.io

Zero-copy, high-performance logfmt parser for Rust. No dependencies.

Logfmt is the key=value structured logging format used by Heroku, Datadog agents, and many Go services.

§Features

  • Zero-copy iterator — yields (&str, &str) slices directly into the input string
  • Owned convenience APIparse_to_map() returns HashMap<String, String> with escape sequences resolved
  • No dependencies — pure Rust, no regex, no allocations in the iterator path
  • Handles quoted strings, \" / \\ / \n / \t escape sequences, and bare keys (no =)

§Usage

§Zero-copy iterator

use tpt_logfmt_parse::LogfmtParser;

let input = r#"level=info msg="hello world" latency=42ms"#;
for pair in LogfmtParser::new(input) {
    let (key, value) = pair.unwrap();
    println!("{key} = {value}");
}

§Owned HashMap

use tpt_logfmt_parse::parse_to_map;

let map = parse_to_map(r#"level=error msg="disk full" retries=3"#).unwrap();
println!("{}", map["msg"]); // disk full

§License

Licensed under either of Apache License 2.0 or MIT at your option. Zero-copy logfmt parser. See LogfmtParser for the streaming iterator API and parse_to_map for the convenience owned-map API.

Structs§

LogfmtError
An error produced during logfmt parsing.
LogfmtParser
Zero-copy streaming logfmt parser.

Functions§

parse_to_map
Parse a logfmt string into an owned HashMap<String, String>.