【发布时间】:2015-02-09 20:37:54
【问题描述】:
我的 Perl 脚本获取文件日志(由 Apache log4j 创建),不知何故,正则表达式命令 \. 下一行没有将所有整行存储到变量中;它工作正常,直到 ErrorType 我的变量消息为空并且@nextline 应该包含整个下一行(任何字符、任何字母、任何特殊符号)。
我试过\. (\D+\S+)
Perl 正则表达式:
while (<$fh>) {
my @fields = m{^
(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:[\d,]+)
\s (INFO | INFO\s | VERBOSE) \s
\[(?: SOAP | GUI )\s[(]User:["](\w+)",\sThreadId:\s\d+\)]
\s com.whatever.whichever.(\S+) \s \(\S+\.PYTHON\:\d+\) \s
- (?! \sUser )
\s (\D+\S+)
\. (\D+\S+) #the all entire next line
$}x
printf('$date=%s; $lovelforlogs=%s; $userid=%s; $methodused=%s; $Errortype=%s; $nextline=%s',@fields );
print "\n";
示例日志条目:
2014-12-10 12:25:13,688 INFO [SOAP (User:"userid", ThreadId: 11)] com.whatever.whichever.program.cache (myMethod.PYTHON:59) - CRITICAL ERROR
; hereSometest#: 368; some other#: 23
at org.JBOSS.xpath.compiler.XPathParser.error(XPathParser.PYTHON:610)
at org.JBOSS.xpath.compiler.XPathParser.initXPath(XPathParser.PYTHON:145)
at org.JBOSS.xpath.XPath.<init>(XPath.PYTHON:227)
at org.JBOSS.xalan.processor.StylesheetHandler.createXPath(StylesheetHandler.PYTHON:155)
at org.JBOSS.xalan.processor.XSLTAttributeDef.processEXPR(XSLTAttributeDef.PYTHON:763)
at org.JBOSS.xa
2015-01-21 12:23:51,681 INFO [SOAP (User:"userid", ThreadId: 83)] com.whatever.whichever.program.cache (myMethod.PYTHON:690) - ERROR
com.whatever.whicever.program.exceptions.InvalidParameterException: F20176 VALUE is WRONG [G00097]
at org.JBOSS.xpath.compiler.XPathParser.error(XPathParser.PYTHON:610)
at org.JBOSS.xpath.compiler.XPathParser.initXPath(XPathParser.PYTHON:145)
at org.JBOSS.xpath.XPath.<init>(XPath.PYTHON:227)
at org.JBOSS.xalan.processor.StylesheetHandler.createXPath(StylesheetHandler.PYTHON:155)
at org.JBOSS.xalan.processor.XSLTAttributeDef.processEXPR(XSLTAttributeDef.PYTHON:763)
at org.JBOSS.xa
2015-01-27 12:24:37,079 VERBOSE [SOAP (User:"userid", ThreadId: 70)] com.whatever.whichever.program.cache (myMethod.PYTHON:2066) - Unchecked error
AxisFault
at org.JBOSS.xpath.compiler.XPathParser.error(XPathParser.PYTHON:610)
at org.JBOSS.xpath.compiler.XPathParser.initXPath(XPathParser.PYTHON:145)
at org.JBOSS.xpath.XPath.<init>(XPath.PYTHON:227)
at org.JBOSS.xalan.processor.StylesheetHandler.createXPath(StylesheetHandler.PYTHON:155)
at org.JBOSS.xalan.processor.XSLTAttributeDef.processEXPR(XSLTAttributeDef.PYTHON:763)
at org.JBOSS.xa
结果应该是:
date=2014-12-10 12:25:13,688 lovelforlogs=INFO userid=userid methodused=myMethod Errortype=CRITICAL ERROR message=; hereSometest#: 368; some other#: 23
date=2014-12-10 12:25:13,688 lovelforlogs=INFO userid=userid methodused=myMethod Errortype=ERROR ERROR message=com.whatever.whicever.program.exceptions.InvalidParameterException: F20176 VALUE is WRONG [G00097]
date=2015-01-27 12:24:37,079 lovelforlogs=VERBOSE userid=userid methodused=myMethod Errortype=Unchecked error message=AxisFault
谢谢
【问题讨论】: