在Java中解析日志文件以仅显示消息

在Java中解析日志文件以仅显示消息,java,parsing,logging,Java,Parsing,Logging,我很难让它工作。我有一个非常大的.log文件,我需要读入代码,我需要对代码进行解析和格式化,然后将其导出到一个文本文档中,以正确的顺序包含正确的信息。以下是我目前的代码: import java.util.*; import java.io.*; public class chatLogParse { public static void main(String args[]) throws IOException { String path = "sampleData.log"; File

我很难让它工作。我有一个非常大的.log文件,我需要读入代码,我需要对代码进行解析和格式化,然后将其导出到一个文本文档中,以正确的顺序包含正确的信息。以下是我目前的代码:

import java.util.*;
import java.io.*;

public class chatLogParse {
public static void main(String args[]) throws IOException {

String path = "sampleData.log";
FileInputStream inputStream = null;
Scanner input = null;
String filename;
// Connecting to a file with a buffer
        PrintWriter outFile = new PrintWriter(
                              new BufferedWriter(
                              new FileWriter("ChatOutput.txt")));

try {inputStream = new FileInputStream(path);
input = new Scanner(inputStream, "UTF-8");
while (input.hasNextLine()) {
    String line = input.nextLine();
    System.out.println(line);
}
// note that Scanner suppresses exceptions
if (input.ioException() != null) {
    throw input.ioException();
}
} finally {
if (inputStream != null) {
    inputStream.close();
}
if (input != null) {
    input.close();
    }
   }
  }
 }
以下是日志文件的一个片段:

08:25:26.668 [D] [T:000FF4] [F:LANTALK2C] <CMD>LANMSG</CMD>
<MBXID>1124</MBXID><MBXTO>5760</MBXTO><SUBTEXT>LanTalk</SUBTEXT><MOBILEADDR>
</MOBILEADDR><LAP>0</LAP><SMS>0</SMS><MSGTEXT>but didn't give me the info I 
needed</MSGTEXT>
08:25:26.672 [+] [T:000FF4] [S:1:1:1124:5607:5] LANMSG [0/2 | 0]
08:25:26.872 [+] [T:000FE8] [S:1:1:1124:5607:5] LANMSGTYPESTOPPED [0/2 | 0]
08:25:28.084 [+] [T:000F1C] [O:TASK] <<< Processing: 0
08:25:29.526 [+] [T:000FEC] [S:1:1:1124:5607:5] LANMSGTYPESTARTED [0/2 | 0]
08:25:31.101 [+] [T:000F1C] [O:TASK] <<< Processing: 0
08:25:34.119 [+] [T:000F1C] [O:TASK] <<< Processing: 0
08:25:34.600 [D] [T:000FF8] [F:LANTALK2C] <CMD>LANMSG</CMD>
<MBXID>1162</MBXID><MBXTO>5607</MBXTO><SUBTEXT>LanTalk</SUBTEXT><MOBILEADDR>
</MOBILEADDR><LAP>0</LAP><SMS>0</SMS><MSGTEXT>i have no clue whats going 
on</MSGTEXT>
08:25:34.610 [+] [T:000FF8] [S:1:1:1162:5760:5] LANMSG [15/2 | 0]
08:25:34.800 [+] [T:000FF0] [S:1:1:1162:5760:5] LANMSGTYPESTOPPED [0/2 | 0]

我需要代码对代码行进行排序,只选择包含LANTALK的行,按时间顺序应用格式和输出,同时丢弃所有其他行。我不知道怎么做。如果您能给我任何帮助,我将不胜感激!谢谢

你有什么特别的问题吗?堆栈溢出不是一项代码编写服务。你们这部分的工作一直在进行。我已经做了4个小时了。我只需要一个方向。你对问题的描述非常准确。休息一下,清醒一下头脑。顺便说一句,前面的注释“a long”拼写正确。可以使用XML解析器解析消息,以获取代码中
[F:LANTALK2C]
后面字符串的
中的值。对于时间部分,只需将空白前读取的第一个字符串的时间转换为最接近的分钟。
8:25:00 AM [John Smith] to [Steve Jobs] but didn't give me the info I needed
8:25:00 AM [John Smith] to [Steve Jobs] i have no clue whats going on