简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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