The syslog-ng application can rewrite parts of log messages: it can search and replace text, and also set a specific field to a specified value. Rewriting messages is often used in conjunction with message parsing Section 3.8, “Parsing messages”.
Rewrite rules are similar to filters: they must be defined in the syslog-ng configuration file and used in the log statement.
![]() |
Note |
|---|---|
The order of filters, rewriting rules, and parsers in the log statement is important, as they are processed sequentially. |
To create replace a part of the log message, define the string or regular expression to replace, the string to replace the original text (macros can be used as well), and the field of the message that the rewrite rule should process. Substitution rules can operate on any value available via macros, e.g., HOST, MESSAGE, PROGRAM, or any user-defined macros created using parsers (see Section 8.6, “Message parsers” for details.). Substitution rules use the following syntax:
Declaration:
rewrite <name_of_the_rule>
{subst("<string or regular expression to find>", "<replacement string>", value(<field name>), flags());};
A single substitution rule can include multiple substitutions that are applied sequentially to the message. Note that rewriting rules must be included in the log statement to have any effect.
![]() |
Tip |
|---|---|
For case-insensitive searches, add the |
To set a field of the message to a specific value, define the string to include in the message, and the field where it should be included. Setting a field can operate on any value available via macros, e.g., HOST, MESSAGE, PROGRAM, or any user-defined macros created using parsers (see Section 8.6, “Message parsers” for details.). Note that this operation completely replaces any previous value of that field. Use the following syntax:
Declaration:
rewrite <name_of_the_rule>
{set("<string to include>", value(<field name>));};
© 2007-2010 BalaBit IT Security
Please send your comments or documentation bugs to: documentation@balabit.com