2012-07-11 29 views
-1

我是新来的Stackoverflow。所以请原谅我,如果我没有完成我的作业彻底搜查。从tomcat localhost log和catalina.out文件解析文本时遇到问题。我们都知道我们会在这些文件中收到严重警报。我想要一个脚本或免费软件,它可以帮助我单独解析SEVERE警报并将邮件发送到我的电子邮件。是否有任何脚本或其他方法来解析tomcat日志?

例如:

SEVERE: Error listenerStart 
6 Jul, 2012 2:04:40 PM org.apache.catalina.core.StandardContext start 
SEVERE: Context [**********] startup failed due to previous errors 
6 Jul, 2012 2:04:40 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 

SEVERE: The web application [**************] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
6 Jul, 2012 2:04:40 PM org.apache.catalina.startup.HostConfig deployWAR 

INFO: Deploying web application archive server.war 
6 Jul, 2012 2:04:40 PM org.apache.catalina.loader.WebappClassLoader validateJarFile 

脚本必须从分析“重度:......”的文字到明年“重度:......”或文件的末尾。该脚本可以在shell或python或ruby中。

+1

如果你知道你没有做好你的研究,那么真的没有任何借口,在那里。 – 2012-07-11 11:07:36

+0

不是脚本,但看看那些主题: http://serverfault.com/questions/63297/good-free-tomcat-log-analyser http://serverfault.com/questions/96720/open-source- tomcat-log-viewer – Pawel 2012-07-11 11:11:17

回答

4

认真吗?

有什么问题像bash脚本:

grep ^SEVERE catalina.out | mail [email protected] 

快照的要求?试试这个:

grep ^SEVERE catalina.out > tmpFile 
diff tmpFile snapshot | mail [email protected] 
mv tmpFile snapshot 
+0

是否可以将其作为cronjob工作?所以只要SEVERE或ERROR被记录,它立即邮寄... – Spidey 2012-07-11 10:40:33

+0

感谢您的grep命令。 Bu收集所有严重警报和邮件。如果脚本反复检查文件,那么每次只解析一个SEVERE警报并将其发送出去会很好。 :) – Spidey 2012-07-11 10:59:03

+0

邮寄时滚动日志?或者像上面那样使用便宜的快照? – 2012-07-11 11:02:53

相关问题