Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Read Log Files for real time reporting

 
Vignesh Sudhakar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello People,

I hope you can help me with this problem. I need to write a java program that reads log files for real time reporting. So these are the catches:

1. The java program needs to run in a linux VM
2. The program should read files from directories in multiple hierarchies

for e.g., My original application writes log files in the following manner: For every transaction, it creates files.

The Directory structure looks like this Application Log Folder 1...n > Year > Month > Day > Hour of the Day > (and it creates new files for every transactions). For next day, it does the same, except it does not create new high level hierarchies of folder but it just moves on inside the old ones like this Year > Month > Next Day > Hour of the Day

Hope I better explained my file structure

My java program has to read every log file for every transaction. Look for a string in every line of the log file and if it finds it, it copies the line and writes the line to a different single file (the program needs to create an output file every day for transactions of a single day)



Now, I know its quite easy to read a file, read every line, look for a string and copy the line over to an output file. But, how do I tackle the directory structures? (It could vary based on application). How can I make this real time so the data is written into the output file after every transaction completes (iow, after every log file is created)

Thanks in Advance
wicke
 
Ashley Bye
Ranch Hand
Posts: 132
2
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not change the folder structure so that you record on a day by day basis rather than hourly? Alternatively, can you set up another logger which just logs the specific transaction information you are interested in at the time of execution and write it to the separate file?
 
Vignesh Sudhakar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashley,

Thanks for answering. But unfortunately, the original application is owned by a 3rd party and I have no control over them and neither can I integrate any logged with it. All I have are the log files written by that app


Thanks,
wicke
 
Ashley Bye
Ranch Hand
Posts: 132
2
Java Mac
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've not used so can't comment on its usage, but have a look at the Oracle tutorial for WatchService API in the java.nio.file package.
 
Vignesh Sudhakar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Ashley. I appreciate your quick response. I will take a look at the service.

I have another question though. Not sure if I can ask in the same forum.

I am developing the program in eclipse IDE. The application should run in a linux VM though. I never worked on linux machines before. So, My question here is:

How do I build the application so it can be run in linux? To be honest, I used to be web developer and know how to handle/deploy the war files but not sure how I should build a java native application to run in different OSs.

Thanks,
Vignesh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!