使用 Google Guava 解析日志
我正在寻找解析具有以下格式的日志(使用 Google Guava)的日志文件的方法:
Sep 19 2006 13:23:40 MyDevice [latency][info] xmlfirewall (loopback-fw): tid(2809): Latency: 0 1 0 1 1 0 0 1 **999** 1 1 1 0 0 1 1 [http://<IP address>:9999/foo/test.xml]
我正在使用 Google Guava 读取日志文件
List < String > lines = Files.readLines(new File("C://my.log"), Charsets.UTF_8);
我想要做的是基于用户输入(开始时间、结束时间、IP 地址) ,我只想选取开始/结束时间之间有 IPAddress 的那些行,然后生成如下所示的输出
Time,DeviceName,LatencyValue - 在上述情况下,输出将为
05:13:40,MyDevice,999
我该怎么办。
I am looking at way of parsing log file having log -- (Using Google Guava) in below format:
Sep 19 2006 13:23:40 MyDevice [latency][info] xmlfirewall (loopback-fw): tid(2809): Latency: 0 1 0 1 1 0 0 1 **999** 1 1 1 0 0 1 1 [http://<IP address>:9999/foo/test.xml]
I am reading log file using Google Guava
List < String > lines = Files.readLines(new File("C://my.log"), Charsets.UTF_8);
What I want to do is based on the user input (Start Time, End Time, IPAddress), I want to pickup only those line where we have IPAddess between start/end time and then produce an output like this
Time,DeviceName,LatencyValue -- In the above case the output will be
05:13:40,MyDevice,999
How Should I go about it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 CharStreams.readLines 方法和 LineProcessor 界面 - 我已经用它来对大文件进行流式解析,效果良好。
Take a look at the CharStreams.readLines method and the LineProcessor interface -- I've used that to do streaming parses of large files with good results.
我认为 Guava 不会在这方面为您提供帮助,而且我个人也不会将文件读取到行列表。
相反,我会使用正则表达式并在整个文本上运行它,如下所示:
I don't think Guava will help you there, and I personally wouldn't read the file to a list of lines, either.
Instead, I'd use a regular expression and run it over the entire text, like so: