我需要从日志文件中识别服务器事件。我为此目的使用模式匹配。我的正则表达式不工作。请检查我的正则表达式是否错误或问题是否在其他地方。
样本输入是:-
2009/12/14 11:49:20.55 00 STARTUP Distributed Access Infrastructure V1.1.0
2009/12/14 11:49:20.55 01 STARTUP Tools Access Server initialization started
2009/12/14 11:49:20.55 TAS#####EC05003E 00 STARTUP Environment:
2009/12/14 11:49:20.55 TAS#####EC05003E 01 STARTUP Job.....DAITAS System...EC05 ASID.....003E
2009/12/14 11:49:20.55 TAS#####EC05003E 02 STARTUP User....USRT001 Group....SYS1 JobNum...STC00079
2009/12/14 11:49:20.55 TAS#####EC05003E 03 STARTUP Local...GMT-08 GMT......2009/12/14 19:49
我的脚本是:
public void map(Object key, Text value, Context context) throws IOException , InterruptedException{
String input=value.toString();
String delimiter= "[\n]";
String[] tokens=input.split(delimiter);
String sample = null;
Pattern pattern;
String regex= " \\s+\\d+\\s+[a-z,A-Z]+\\s ";
pattern=Pattern.compile(regex);
for(int i=0;i<tokens.length;i++){
sample=tokens[i];
System.out.println(sample.toString());
System.out.println("enter here");
Matcher match=pattern.matcher(sample);
boolean val = match.matches();
System.out.println("the conditions" + val);
System.out.println("enter here 2");
if(val){
System.out.println("the regex is found" + val);
logEvent.set(sample);
System.out.println("the value of logEvent is "+ logEvent);
}
else{
logInformation.set(sample);
System.out.println("the log informaTION" + logInformation);
}
context.write(logEvent, logInformation);
我需要认识——启动
谢谢