- 论坛徽章:
- 15
|
本帖最后由 rdcwayx 于 2014-07-18 19:34 编辑
这个是 position-based extraction:- %propname:fromChar:toChar:options:fieldname%
复制代码 加了R后,就是regex 格式:- R,<regexp-type>,<submatch>,<nomatch>,<match-number>
复制代码 看这个介绍里的黑体部分,也就是R:后面的都是正则,但是以冒号分割,前一部分是fromChar, 后一部分是 toChar.
There is also support for regular expressions. To use them, you need to place a "R" into FromChar. This tells rsyslog that a regular expression instead of position-based extraction is desired. The actual regular expression must then be provided in toChar. The regular expression must be followed by the string "--end". It denotes the end of the regular expression and will not become part of it. If you are using regular expressions, the property replacer will return the part of the property text that matches the regular expression. An example for a property replacer sequence with a regular expression is: "%msg:R:.*Sev:. \(.*\) \[.*--end%"
regexp-type is either "BRE" for Posix basic regular expressions or "ERE" for extended ones. The string must be given in upper case. The default is "BRE" to be consistent with earlier versions of rsyslog that did not support ERE. The submatch identifies the submatch to be used with the result. A single digit is supported. Match 0 is the full match, while 1 to 9 are the acutal submatches. The match-number identifies which match to use, if the expression occurs more than once inside the string. Please note that the first match is number 0, the second 1(我加的解释: the second match is number 1) and so on. Up to 10 matches (up to number 9) are supported. Please note that it would be more natural to have the match-number in front of submatch, but this would break backward-compatibility. So the match-number must be specified after "nomatch".
这个例子中, .*Serv 是起始部分 (也就是Serv 前的所有字符包括Serv), . \(.*\) \[.* 是最后的部分,.(任意字符) [任意字符
"%msg:R:.*Sev:. \(.*\) \[.*--end%"
这个例子里, R说明是regex ,格式是ERE (extended regex), 第一个1 是submatch,FIELD 是 nonmatch,第二个 1 是匹配数,1代表第二次匹配。
“%msg:R,ERE,1,FIELD,1:for (vlan[0-9]\*):--end%”- Mode Returned
- DFLT "**NO MATCH**"
- BLANK "" (empty string)
- ZERO "0"
- FIELD full content of original field
复制代码 参考资料:
http://w.gdu.me/wiki/Linux/rsyslog_logrotate.html
http://www.cnblogs.com/tobeseeker/archive/2013/03/10/2953250.html
http://www.rsyslog.com/doc/property_replacer.html
http://www.rsyslog.com/doc/rsyslog_conf_nomatch.html |
|