我需要将日志文件转换为XSL表格 - 我的日志文件格式如下 -
73445971 [WebContainer : 3] ERROR ERROR.com.xyz.cat.csd.datarqst.model.DataRequestCollection - {Event Id=9248285763 | Time=2015-05-25-00.22.11.822000 | Event Type=ERROR | Request Id=_3AcuNq3qj_G4OmM7Z3DmCS | Lifecycle=qa | Application Id=XYZ | Application Version=2015-05-21-015732 | Host Name=lzbita18 | Server Instance=18_CL1_WEB20_QA_M1 | Client Descriptor=Sxyz | User Id=@1224 | Request Descriptor=https://abcb04.xyz.com/csd/alert.do | Session Id=_3AcuNq3qj_G4OmM7Z3DmCS | Session Create Timestamp=2015-05-25-00.19.03.326000 | Global Session Id=231cf811:_3AcuNq3qj_G4OmM7Z3DmCS | Remote Address=10.230.9.164 | Message=Missing provision for Data Request: | Method=getDataRequest() | Severity=ERROR}
77379848 [WebContainer : 3] ERROR ERROR.com.xyz.cat.csd.connectivity.ConnectivityException - {Event Id=1823361457 | Time=2015-05-25-01.27.45.697000 | Event Type=ERROR | Request Id=mKHEL__UTfhAu8qOSHRQhhp | Lifecycle=qa | Application Id=XYZ | Application Version=2015-05-21-015732 | Host Name=lzbita18 | Server Instance=18_CL1_WEB20_QA_M1 | Client Descriptor=ZYX | User Id=1225 | Request Descriptor=https://abc04.xyz.com/csd/clntPrvsn.do | Session Id=mKHEL__UTfhAu8qOSHRQhhp | Session Create Timestamp=2015-05-25-01.26.22.442000 | Global Session Id=0:mKHEL__UTfhAu8qOSHRQhhp | Remote Address=10.229.14.121 | Message=Exception in thread for module: 20, adapter: com.xyz.cat.csd.connectivity.adapter.WebServiceAdapter: exceeded max time. | Method=com.xyz.cat.csd.connectivity.AbstractDao.adapterException(AbstractDao.java:423) | Severity=ERROR | Stack Trace=com.xyz.cat.csd.connectivity.ConnectivityException: Exception in thread for module: 20, adapter: com.xyz.cat.csd.connectivity.adapter.WebServiceAdapter: exceeded max time.
at com.xyz.cat.csd.connectivity.AbstractDao.adapterException(AbstractDao.java:423)
at com.xyz.cat.csd.connectivity.AbstractDao.process(AbstractDao.java:313)
... 33 more}
列将根据管道分隔符' |'分隔。
我要找的是格式值应该在定义的列中,而堆栈跟踪的值应该在一行中,该列在多行中并以(om.xyz.cat.csd.connectivity.AbstractDao.process结束) (AbstractDao.java:313) ... 33更多}) 下面是我试图在代码下面使用的代码 -
类OpenL实现了ActionListener { public void actionPerformed(ActionEvent e) { final JFileChooser c = new JFileChooser(); //展示"打开"对话: int rVal = c.showOpenDialog(FileChooserTest.this); if(rVal == JFileChooser.APPROVE_OPTION) { filename.setText(c.getSelectedFile()的getName()); dir.setText(c.getCurrentDirectory()的toString());
try
{
File logFile = c.getSelectedFile();
FileInputStream fstream = new FileInputStream(logFile);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
StringBuffer sb = new StringBuffer();
sb
.append("Event Id, Time, Event Type, Request Id, Lifecycle, Application Id, Application Version, Host Name, "
+ "Server Instance, Client Descriptor, User Id, Request Descriptor, Session Id, Session Create Timestamp, Global Session Id, Remote, Address, Message, Method, Severity, Stack Trace ");
sb.append("\n");
while ((strLine = br.readLine()).isEmpty()
|| (strLine = br.readLine()) != null
|| !(strLine = br.readLine()).equals(""))
{
if (strLine.contains("{"))
{
String str = strLine.substring(strLine.indexOf("{") + 1, strLine.length() - 1);
String[] tokens = str.split("\\|");
for (String token : tokens)
{
String value = token.substring(token.indexOf("=") + 1, token
.length());
sb.append(value);
sb.append(",");
}
}
sb.append("\n");
}
br.close();
Writer writer = null;
try
{
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:/Users/xyz/Desktop/CSPro.csv"), "utf-8"));
writer.write(sb.toString());
}
catch (IOException ex)
{
// report
}
finally
{
try
{
writer.close();
}
catch (Exception ex)
{
}
}
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
if (rVal == JFileChooser.CANCEL_OPTION)
{
filename.setText("You pressed cancel");
dir.setText("");
}
}
}