简体   繁体   中英

Read log file from a particular timestamp in java

I am reading a log file line by line (using BufferedReader) & extracting data from each line. The log file has some ip, timestamp on each line & the service that was invoked at that time & the status of the call.

Sample line from the log:

10.435.234.220 - - [14/Jul/2014:08:07:07 -0700] "GET /resources/getQuote HTTP/1.1" 200 962 10.435.235.123 - - [14/Jul/2014:09:31:41 -0700] "GET /resources/getOpp HTTP/1.1" 200 962

The above is working fine.

But the next time I run the code, i want to extract data only from lines after the timestamp that was read the last time.

Say, The first time, it extracted data till the line with timestamp 14/Jul/2014:08:07:07, the next time, i want to extract data after that line. How to do this. Any help will be great.

(sorry cannot comment yet)

You need to persist the state between the executions.
Just save the last line, or the line number to a file, or database.

The very next run, start reading from the line# you saved.

Here is an example of reading file from a specific line#: java: how to use bufferedreader to read specific line

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