If you use Logtail to collect logs, you can use the processor_string_replace plug-in to replace specific strings by specifying a string or a regular expression, or removing escape characters. This topic describes the parameters that are used to configure the processor_string_replace plug-in and provides configuration examples.
Plug-in configuration description
Important
Logtail V1.6.0 or later supports the processor_string_replace plug-in.
Form configuration
Editor configuration in JSON
Set the Processor Type parameter to String Replacement. Then, configure other parameters based on the following table.
Parameter | Description |
Original Field | The name of the original field. |
Match Mode | The method that is used to replace the content. Valid values: String Match: replaces the content that matches a specified string with a different string. Regex Match: replaces the content that matches a specified regular expression with a string. Remove Escape Character: removes escape characters.
|
Matched Content | The content that you want to replace. If you set the Match Mode parameter to String Match, specify a string that you want to replace. If multiple strings are matched, all matched strings are replaced. If you set the Match Mode parameter to Regex Match, specify a regular expression that you want to use to match specific content. If multiple strings are matched, all matched strings are replaced. You can also use the group method in a regular expression to match specified groups. If you set the Match Mode parameter to Remove Escape Character, you do not need to configure this parameter.
|
Replaced By | The string that is used to replace the matched content. If you set the Match Mode parameter to String Match, specify a string that you want to use to replace the matched content. If you set the Match Mode parameter to Regex Match, specify a string that you want to use to replace the matched content. You can also use the group method in a regular expression. If you set the Match Mode parameter to Remove Escape Character, you do not need to configure this parameter.
|
New Field | The new field that is assigned to the string used to replace the matched content. |
Set the type
parameter to processor_string_replace
. Then, configure other parameters in detail
based on the following table.
Parameter | Type | Required | Description |
SourceKey
| String | Yes | The name of the original field. |
Method
| String | Yes | The method that is used to replace the content. Valid values: const : replaces the content that matches a specified string with a different string.
regex : replaces the content that matches a specified regular expression with a string.
unquote : removes escape characters.
|
Match
| String | No | The content that you want to replace. If you set the Method parameter to const , specify a string that you want to replace. If multiple strings are matched, all matched strings are replaced. If you set the Method parameter to regex , specify a regular expression that you want to use to match specific content. If multiple strings are matched, all matched strings are replaced. You can also use the group method in a regular expression to match specified groups. If you set the Method parameter to unquote , you do not need to configure this parameter.
|
ReplaceString
| String | No | The string that is used to replace the matched content. Default value: "". If you set the Method parameter to const , specify a string that you want to use to replace the matched content. If you set the Method parameter to regex , specify a string that you want to use to replace the matched content. You can also use the group method in a regular expression. If you set the Method parameter to unquote , you do not need to configure this parameter.
|
DestKey
| String | No | The new field that is assigned to the string used to replace the matched content. By default, no new fields are added. |
Configuration examples
Replace the content that matches a specified string
Replace Error:
in the value of the content
field with an empty string.
Form configuration
Editor configuration in JSON
Replace the content that matches a specified regular expression
Replace the string that matches the \\u\w+\[\d{1,3};*\d{1,3}m|N/A
regular expression in the value of the content
field with an empty string.
Form configuration
Editor configuration in JSON
Use the group method in a regular expression to match specified groups
Use the group method in a regular expression to replace 16
in the value of the content
field with */24
and specify the new_ip
field to store */24.
Important
If you use the group method in a regular expression, the string that is used to replace the matched content cannot contain braces ({}
). You can specify a string in the $1
or $2
format.
Form configuration
Editor configuration in JSON
Remove escape characters
Form configuration
Editor configuration in JSON