• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Retriving data from a log file

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everbody,

We have a requirement that i should retrive latest data(information) from the log file.This log file will be updating ever 15 minutes.So when the user requested at particular time(say at 10.00AM),we should be able to get that data only.

Please suggest how to go forward
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Babu.

A naive strategy would be to open the log file using standard I/O and start looking for the requested timestamp (I suppose the log file has such information).
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On one small server I have a log writer that writes to a circular buffer in memory. Once it is full, the new entries overwrite the oldest. I don't know if you could afford the memory to build such a thing using age to grow and shrink the buffer - maybe a LinkedList - as time goes by. Here's a snippet from my workstation:
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another idea, in pseudocode:

Note that when you use the skip() method to skip bytes, you generally need to use a loop to make sure that it really skips all the bytes you requested:


Depending on the operating system and how your logging works, you may or may not sometimes see a file that appears to end with an incomplete line, because the file is being written at the same time you're trying to read it. If you encounter this phenomenon, perhaps you can save the last line read in memory, and add it to whatever is read the next time you read the file. Or perhaps this in an unnecessary complication. You'll have to test and see what happens, I think.
reply
    Bookmark Topic Watch Topic
  • New Topic