简体   繁体   English

Java中的日志文件解析器

[英]Log File Parser in Java


I am trying to design Log File Parser for my application. 我正在尝试为我的应用程序设计日志文件解析器。 I have thousands of Log files having same pattern of data and my objective is to first parse the data and store it in a database. 我有成千上万个具有相同数据模式的日志文件,我的目标是首先解析数据并将其存储在数据库中。
Log file has following pattern- 日志文件具有以下模式-

a=some_value_1 b=some_value_2 c=some_value_3 d=some_value_4
a=some_value_5 b=some_value_6 c=some_value_7 d=some_value_8
a=some_value_9 b=some_value_10 c=some_value_11 d=some_value_12
a=some_value_13 b=some_value_14 c=some_value_15 d=some_value_16

My initial idea is to read all the files line by line using InputStreamReader and for every file in every line pick the data and fetch it to db. 我最初的想法是使用InputStreamReader逐行读取所有文件,并为每一行中的每个文件选择数据并将其提取到db。 Seems good for some files but performance wise i need to improve my design. 对于某些文件来说似乎不错,但在性能方面我需要改进设计。 Can somebody suggest some better design model/architecture for the same? 有人可以建议相同的一些更好的设计模型/架构吗?

I suggest that it will be better to use BufferedReader instead of InputStreamReader . 我建议最好使用BufferedReader而不是InputStreamReader The parsing part of your task does not seem very hard now. 现在,任务的解析部分似乎并不困难。

Patterns are great, but you should use them only when they make sense. 模式很棒,但只有在有意义的情况下才应使用它们。 No special pattern required here: just iterate over the files; 这里不需要特殊的模式:只需遍历文件即可; for each file, read it, and do the inserts as required. 对于每个文件,请阅读并按要求进行插入。 The program should not take up more than 50 lines in a single file/class with a main[] method. 使用main []方法,该程序在单个文件/类中最多占用50行。 Small, clean code is much better than complex, large code. 小而干净的代码比大而复杂的代码好得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM