• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Read Log Files for real time reporting

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 146
2
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 146
2
Mac Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic