pub struct Grok { /* private fields */ }
Expand description
The Grok
struct is the main entry point into using this library.
Implementations§
Source§impl Grok
impl Grok
Sourcepub fn with_default_patterns() -> Self
pub fn with_default_patterns() -> Self
Creates a new Grok
instance and loads all the default patterns.
For more information, see the patterns
module.
Sourcepub fn add_pattern<S: Into<String>>(&mut self, name: S, pattern: S)
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{..}
.
Sourcepub fn compile(
&self,
pattern: &str,
with_alias_only: bool,
) -> Result<Pattern, Error>
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 Default for Grok
The Default implementation for Grok whuich will load the default patterns.
impl Default for Grok
The Default implementation for Grok whuich will load the default patterns.
Source§impl<S: Into<String>, const N: usize> From<[(S, S); N]> for Grok
Allows to construct Grok with an array of patterns directly.
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._-]+")]);