当Regex模式匹配时,仅解析并打印堆栈跟踪

时间:2017-08-24 06:22:09

标签: java

我想打印从at cab.ces.upgrade.controller.UpgradeRecommendationController.getPackageOffers(UpgradeRecommendationController.java:1234)开始的堆栈跟踪。这就是我输出的方式。 **** Error Wed Jul 05 23:23:49 GMT 2017 1499297029577 /lll/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-23596/cab/ces/upgrade/manager/business/UpgradeRecommendationsBusinessManager at cab.ces.upgrade.controller.UpgradeRecommendationController.getPackageOffers(UpgradeRecommendationController.java:1234)

所以我需要删除**** Error Wed Jul 05 23:23:49 GMT 2017 1499297029577 /lll/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-23596/cab/ces/upgrade/manager/business/UpgradeRecommendationsBusinessManager

我的代码

if((strLine.contains("**** Error") )){
                            //|| (strLine.contains("(CreditCheckManager")
                            //String sPattern = "\\tat (.*)\\.(.*)\\(([^:]*):?([\\d]*)\\)";
                        Matcher m = p.matcher(strLine);
                        if(m.find()){
                            totCount++;
                            iCount++;

                        if((iCount==1) ){
                            System.out.println("Class name:- " + m.group(3));
                            System.out.println("Line Number:- " + m.group(4));
                            System.out.println();
                            System.out.println("VodafoneSystemException occurence count: " + exCount);
                            System.out.println();
                            System.out.println("VodafoneSystemException stack trace count: " + totCount);

                        }

                        System.out.println(strLine);

1 个答案:

答案 0 :(得分:0)

使用at (.)+查找之后的所有字符串,请参阅regex