我无法改变的遗留系统每天都会输出5千兆个非常糟糕的XML日志并烧毁我的摄取许可证。 有两类冗长错误每分钟发生1000次以上,但每隔几分钟就有一次真正有趣的条目。 我想彻底缩短sed中的重复条目,并保持有趣的条目不受影响
所以我需要什么
1.正则表达式匹配两类恼人的日志条目中的每一类(例如......'十进制' ...和......' DBNull' ...但不是偶尔有趣的那些)。
一个正则表达式匹配每个烦人的错误类很好,我可以做2 sed传递
2.我需要一个带有时间戳的捕获组,因此我可以用简洁的版本替换长XML行 - 但是使用正确的时间戳,以免失去保真度。
我已经达到这个目标,以匹配捕获创建日期:
(?:<Log).*?(createdDate="\d{2}\/\d{2}\/\d{4}.\d{2}:\d{2}:\d{2}").*?(?:decimal).*?(<\/Log>)
虽然很接近,但却遭遇了一种反向贪婪,我在那里匹配了来自小数的&#39;之前的几个条目的开放日志语句 玩过负面的后卫但只是给自己一个严重的头痛
样本数据
<Log type="ERROR" createdDate="11/09/2015 08:13:14" >
<![CDATA[ [108] -- much cruft removed-- SerializationException: There was an error deserializing the object of type Common.DataCtract.QResult. The value '' cannot be parsed as the type 'decimal'. ---> System.Xml.XmlException: The value '' cannot be parsed as the type 'decimal'. ---> System.FormatException: Input string was not in a correct format.
]]></Log>
<Log type="ERROR" createdDate="11/09/2015 08:13:13" >
<![CDATA[ [108] -- much cruft removed-- SerializationException: There was an error deserializing the object of type Common.DataCtract.QResult. The value '' cannot be parsed as the type 'decimal'. ---> System.Xml.XmlException: The value '' cannot be parsed as the type 'decimal'. ---> System.FormatException: Input string was not in a correct format.
]]></Log>
<Log type="ERROR" createdDate="11/09/2015 08:13:12" >
<![CDATA[ [129] Services.DService.D.FailedToAddRQ(Exceptionex, RQEntityrQ, RHeaderEntityrHeader, StringPRef, ): FailedToAddRQ()...with parameters [pRef:=123,0,1], [rQ.AffinityCode:=],[Q.thing=thing][rQ.AffinityRQDT:=123],[rHeader.RHeaderIDPK:=123],[rQ.UWriteIDFK:=]
Data.DataAccessLayerException: Conversion from type 'DBNull' to type 'Long' is not valid.
Parameters:
[RETURN_VALUE][ReturnValue] Value: [0]
---> System.InvalidCastException: Conversion from type 'DBNull' to type 'Long' is not valid.
]]></Log>
<Log type="ERROR" createdDate="11/09/2015 08:13:11" >
<![CDATA[ [129] Services.DService.D.FailedToAddRQ(Exceptionex, RQEntityrQ, RHeaderEntityrHeader, StringPRef, ): FailedToAddRQ()...with parameters [pRef:=123,0,1], [rQ.AffinityCode:=],[Q.thing=thing][rQ.AffinityRQDT:=123],[rHeader.RHeaderIDPK:=123],[rQ.UWriteIDFK:=]
Data.DataAccessLayerException: Conversion from type 'DBNull' to type 'Long' is not valid.
]]></Log>
<Log type="ERROR" createdDate="11/09/2015 08:13:10" >
<![CDATA[ [231] An actual interesting log entry with a real error message ]]></Log>
<Log type="ERROR" createdDate="11/09/2015 08:13:09" >
<![CDATA[ [108] -- much cruft removed-- SerializationException: There was an error deserializing the object of type Common.DataCtract.QResult. The value '' cannot be parsed as the type 'decimal'. ---> System.Xml.XmlException: The value '' cannot be parsed as the type 'decimal'. ---> System.FormatException: Input string was not in a correct format.
]]></Log>