Struct Grok

Source
pub struct Grok { /* private fields */ }
Expand description

The Grok struct is the main entry point into using this library.

Implementations§

Source§

impl Grok

Source

pub const fn empty() -> Self

Creates a new Grok instance with no patterns.

Source

pub fn with_default_patterns() -> Self

Creates a new Grok instance and loads all the default patterns.

For more information, see the patterns module.

Source

pub fn add_pattern<S: Into<String>>(&mut self, name: S, pattern: S)

Adds a custom grok pattern.

A grok pattern is a standard regular expression string with grok pattern placeholders embedded in it.

The grok pattern placeholders are of the form %{name:alias:extract=definition}, where name is the name of the pattern, alias is the alias of the pattern, extract is the extract of the pattern, and definition is the definition of the pattern.

  • name is the name of the pattern and is required. It may contain any alphanumeric character, or _.
  • alias is the alias of the pattern and is optional. It may contain any alphanumeric character, or any of _-[].. If extract is provided, alias may be empty.
  • extract is the extract of the pattern and is optional. It may contain any alphanumeric character, or any of _-[]..
  • definition is the definition of the pattern and is optional. It may contain any character other than { or }.

A literal % character may appear in a grok pattern as long as it is not followed by {. You can surround the percent with grouped parentheses (%){..}, a non-capturing group (?:%){..}, or use the \x25 escape sequence, ie: \x25{..}.

Source

pub fn compile( &self, pattern: &str, with_alias_only: bool, ) -> Result<Pattern, Error>

Compiles the given pattern, making it ready for matching.

Specify with_alias_only to only include the aliases in the matches rather that all named patterns. This may result in a more efficient compiled pattern.

Trait Implementations§

Source§

impl Debug for Grok

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Grok

The Default implementation for Grok whuich will load the default patterns.

Source§

fn default() -> Grok

Returns the “default value” for a type. Read more
Source§

impl<S: Into<String>, const N: usize> From<[(S, S); N]> for Grok

Allows to construct Grok with an array of patterns directly.

Example:

let mut grok = Grok::from([("USERNAME", r"[a-zA-Z0-9._-]+")]);
Source§

fn from(arr: [(S, S); N]) -> Self

Converts to this type from the input type.
Source§

impl<S: Into<String>> FromIterator<(S, S)> for Grok

Allows to initialize Grok with an iterator of patterns.

Example:

let patterns = [("USERNAME", r"[a-zA-Z0-9._-]+")];
let mut grok = Grok::from_iter(patterns.into_iter());
Source§

fn from_iter<I: IntoIterator<Item = (S, S)>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl Freeze for Grok

§

impl RefUnwindSafe for Grok

§

impl Send for Grok

§

impl Sync for Grok

§

impl Unpin for Grok

§

impl UnwindSafe for Grok

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.