Expand description
grok-rs is a Rust implementation of the Grok pattern matching library.
The captured group can be renamed based on the alias, and the value can be converted to the specified type. The supported types are:
- int
- long
- float
- double
- bool
§Usage
Initiate a Grok instance with the default patterns, or add custom patterns,then compile the your pattern, and parse the input string based on the pattern.
use std::collections::HashMap;
use grok_rs::{Grok, Value};
let mut grok = Grok::default();
grok.add_pattern("NAME", r"[A-z0-9._-]+");
let pattern = grok.compile("%{NAME}", false).unwrap();
let expected: HashMap<String, Value> = [("NAME", "admin")]
.into_iter()
.map(|(k, v)| (k.to_string(), Value::String(v.to_string())))
.collect();
assert_eq!(expected, pattern.parse("admin").unwrap());
assert_eq!(expected, pattern.parse("admin user").unwrap());