Crate grok_rs

Source
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
  • boolean

If the type is not specified, then the value will be kept as string.

§Usage

Initiate a Grok instance which includes the default patterns, or add custom patterns, then compile your whole 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::from([("NAME".to_string(), Value::String("admin".into()))]);

assert_eq!(expected, pattern.parse("admin").unwrap());
assert_eq!(expected, pattern.parse("admin user").unwrap());

Structs§

Grok
Pattern

Enums§

Value