You can configure the Key/Value Pair (KVP) parser for both FileLog
and WinLog
collectors.
Key/Value Pair (KVP) Parser
kvp
parser finds and extracts all
key=value
matches from an arbitrary log message text. The following example shows the
kvp
parser format.
[parser|kvp_parser] base_parser=kvp fields=*
For example, the key-value log can be in the following format: scope=local; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0;
With the kvp
parser, you must specify the fields from which the values are to be extracted. For example, if the definition fields=name,lastname,country
exists in the configuration, only the values with the specified keys are parsed and sent to the server.
Both the key and the value can be optionally surrounded by double quotes “ “ to define white space or other special characters.
When double quotes are used for the key or value, the backslash character “ \ “ can be used as the escape character. Any character following the backslash character is defined literally, including a double quote character or a backslash character. For example: “ \\ ”
Note the following considerations.
- If the key in a key/value pair is not followed by an equals sign and a
VALUE
is not provided, the option is skipped, as with free text. - The key cannot be empty, the value can be empty.
- An equals sign that is not followed by a value is treated as free text and is skipped.
- A value can be a string of characters that are surrounded by double quote characters, or it can be empty. Use a backslash for escaping special characters that are part of the value.
KVP Parser Options
Note the following information about the structure of the kvp
parser.
Option | Description |
---|---|
fields |
The information that you want to extract described as units of data. For example, If specific field names are defined by the If the |
delimiter |
Optional. Default delimiters are the space character, tab, newline characters, comma, and semicolon characters. If delimiters are not specified in the configuration, the To change the default delimiters to specific delimiters, you must define them between double quotes. For example: For example, the |
field_decoder |
Nested parsers are specified as a JSON string in which the keys are the names of the field to apply to the nested parser, and the value is the name of the parser to use for that field. Each nested parser is applied to the appropriate field, as decoded by the base parser. Field decoders are useful when the value of a key-value pair is a complex value such as a timestamp or a comma-separated list. |
debug = |
Optional. The When the option is set to |
Additional Keys Value Options
Key | Definition |
---|---|
KVP_MESSAGE = *(MESSAGE_ENTRY [WSPR]) |
A list of message entries separated by optional white space |
MESSAGE_ENTRY = KVP / FREE_TEXT |
An entry is a key/value pair or just a free text |
KVP = KEY ["=" VALUE] |
Key/value pair. If KEY is not followed by an equal sign and VALUE, it is skipped like free text. |
KEY = BARE_KEY / QUOTED_KEY |
|
FREE_TEXT = "=" |
A free standing equal sign is considered a free text and is skipped. |
BARE_KEY = *1BARE_KEY_CHAR |
At least one character |
BARE_KEY_CHAR = %0x00-08 / %0x10-19 / %0x21-3C / %3E-%FF |
Any character excluding equal sign, space, or TAB |
QUOTED_KEY = 0x22 *1(QUOTED_STRING_CHAR / "\" CHAR) 0x22 |
At least one character surrounded by double quote characters. The backslash is used as an escape character. |
QUOTED_STRING_CHAR = %0x00-21 / %0x23-FF |
Any character excluding double quote |
VALUE = BARE_VALUE / QUOTED_VALUE |
|
BARE_VALUE = *BARE_VALUE_CHAR |
Zero or more characters |
BARE_VALUE_CHAR = %0x00-08 / %0x10-19 / %0x21-FF |
Any character excluding space or TAB |
QUOTED_VALUE = 0x22 *(QUOTED_STRING_CHAR / "\" CHAR) 0x22 |
A string of characters surrounded by double quote characters. This can be empty. The backslash is used as an escape character. |
KVP Parser Configuration Examples
You can use fields=*
to parse all fields, if necessary.
[parser|simple_kvp] base_parser =kvp fields=*
This example shows how to specify the field decoder.
[parser|mykvp] debug=no base_parser=kvp delimiter="#^|" fields=* ;OR fields=scope,abstract,lazyInit,autowireMode,dependencyCheck field_decoder={"field1":"field1_parser1"} [parser|field1_parser1] base_parser=clf format=[%{value1}i]] field_decoder={"value1":"field_parser2"}
To parse the following KVP log:
Configuring transport... proto = cfapi server_hostname = LOCALHOST ssl = no port = 9000 reconnect = 30
[parser|kvp_log_parser] base_parser=kvp fields=*The KVP parser returns the following fields:
proto=cfapi server_hostname=LOCALHOST ssl=no port=9000 reconnect=30
=
) is preceded by a randomly generated key, it is a best practice not to use the KVP parser with the
*
option, because it generates many random fields, which might lead to UI and query performance issues. Instead, you can use the parser by specifying the fields that need to be parsed.
Simple and Complex KVP Parser Examples
Simple KVP Parser Example
[filelog|MyLog] directory=C:\<folder_name>\Parser_logs include=*.log parser=my_KVP_parser [parser|my_KVP_parser] base_parser=kvp fields=*
Complex KVP Parser Example
[filelog|MyLog] directory=C:\<folder_name>\Parser_logs include=*.log parser=my_KVP_parser [parser|my_KVP_parser] base_parser=kvp fields=* field_decoder={"field1":" field1_parser1"} [parser| field1_parser1] base_parser=clf format=[%{value1}i]] field_decoder={"value1":" field1_parser2"}