00001 package ceylan.parser;
00002
00003 import java.text.SimpleDateFormat;
00004 import java.util.Date;
00005 import java.util.regex.Matcher;
00006 import java.util.regex.Pattern;
00007
00008 import com.lightysoft.logmx.business.ParsedEntry;
00009 import com.lightysoft.logmx.mgr.LogFileParser;
00010
00011
00012
00029 public class CeylanParser extends LogFileParser
00030 {
00031
00033 private ParsedEntry entry = null;
00034
00035
00037 private final static SimpleDateFormat DatePattern = new SimpleDateFormat(
00038 "dd/MM/yyyy HH:mm:ss" ) ;
00039
00041 private final static Pattern TraceBeginPattern =
00042 Pattern.compile("^<\\d++\\.\\d++\\.\\d++>\\|.*$");
00043
00044
00049 public String getParserName()
00050 {
00051 return "Ceylan Parser" ;
00052 }
00053
00054
00059 public String getSupportedFileType()
00060 {
00061 return "LogMX Ceylan log files" ;
00062 }
00063
00064
00069 protected void parseLine(String line) throws Exception
00070 {
00071
00072
00073 if (line == null)
00074 {
00075 if (entry != null)
00076 {
00077 addEntry(entry) ;
00078 }
00079 return ;
00080 }
00081
00082 Matcher matcher = TraceBeginPattern.matcher(line) ;
00083
00084 if ( matcher.matches() )
00085 {
00086
00087
00088
00089
00090 String[] fields = line.split( "\\|" ) ;
00091
00092 if (entry != null)
00093 {
00094
00095 addEntry(entry) ;
00096 }
00097
00098 entry = createNewEntry() ;
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 entry.setThread( fields[0].trim() ) ;
00117 entry.setEmitter( fields[2].trim() + "." + fields[1].trim() ) ;
00118 entry.setDate( fields[3].trim() );
00119 entry.setLevel( fields[7].trim() ) ;
00120
00121
00122
00123
00124
00125
00126 entry.setMessage( "[" + fields[6].trim() + "] [" + fields[4].trim()
00127 + "] [" + fields[5].trim() + "]\n" + fields[8].trim() ) ;
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 entry.setExtraInfo( fields[3].trim() );
00140
00141 }
00142 else if (entry != null)
00143 {
00144
00145 entry.setMessage( entry.getMessage() + "\n" + line ) ;
00146 }
00147
00148 }
00149
00150
00151
00161 public Date getRelativeEntryDate(ParsedEntry pEntry) throws Exception
00162 {
00163 return new Date(
00164 Integer.parseInt( pEntry.getExtraInfo().toString() ) ) ;
00165 }
00166
00167
00173 public Date getAbsoluteEntryDate(ParsedEntry pEntry) throws Exception
00174 {
00175
00176 return DatePattern.parse( pEntry.getDate() ) ;
00177
00178 }
00179
00180 }