Log File Parser in Java

我的梦境 提交于 2020-01-16 08:47:29

问题



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. 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?


回答1:


I suggest that it will be better to use BufferedReader instead of InputStreamReader. The parsing part of your task does not seem very hard now.




回答2:


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. Small, clean code is much better than complex, large code.



来源:https://stackoverflow.com/questions/11784032/log-file-parser-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!