Using Regular Expressions to Refine the Set of Logged Messages
The predefined facilities group together related messages, but you can also use regular expression matching to specify more exactly which messages from a facility are logged to a file, a user terminal, or a remote destination.
To specify the text string that must (or must not) appear in a message for the message to be logged to a destination, include the
matchstatement and specify the regular expression which the text string must match:match "regular-expression";You can include this statement at the following hierarchy levels:
[edit system syslog filefilename](for a file)[edit system syslog user (username| *)](for the terminal session of one or all users)[edit system syslog host (hostname| other-routing-engine)](for a remote destination)When you specify the regular expression, use the notation defined in POSIX Standard 1003.2 for extended (modern) UNIX regular expressions. Explaining regular expression syntax is beyond the scope of this document, but POSIX standards are available from the Institute of Electrical and Electronics Engineers (IEEE,
http://www.ieee.org).Table 13 specifies which character or characters are matched by some of the regular expression operators that you can use in the
matchstatement. In the descriptions, the term term refers to either a single alphanumeric character or a set of characters enclosed in square brackets, parentheses, or braces.
Example: Using Regular Expressions
Filter messages that belong to the
interactive-commandsfacility, directing those that include the stringconfigureto the terminal of therootuser:[edit system syslog]user root {interactive-commands any;match ".*configure.*";}Messages like the following appear on the
rootuser's terminal when a user issues aconfigurecommand to enter configuration mode:timestamprouter-namemgd[PID]: UI_CMDLINE_READ_LINE: User 'user', command 'configure private'Filter messages that belong to the
daemonfacility and have severityerroror higher, directing them to the file/var/log/process-errors. Omit messages generated by the snmpd process, instead directing them to the file/var/log/snmpd-errors:[edit system syslog]file process-errors {daemon error;match "!(.*snmpd.*)";}file snmpd-errors {daemon error;match ".*snmpd.*";}