Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How can I pull info from a Log file, and post it in Delphi? Posted by t0ne on 3 Jul 2002 at 12:27 PM
Hey all, I have a small question. What i'm wanting to do, is probably pretty simple, but I'm truthfully lost as I'm merely a newbie delphi boy. Don't get me wrong though, I know enough about delphi to make master/detail reports, but when it comes to interacting with files, reading a line, and then posting what is found, heh, i'm kinda at a loss..

So, here is my problem. I have a small network setup at my house, that I use for sharing files. When someone accesses my network, what they are doing is logged into a log file ( let's call it bob.log ). Now, when I need to search for a specific date to see what joe henry was doing on january 28, 2002, I am gonnna have to go through hundreds of different dates and happenings before I finally come across the line that has the date that i need to see.

What the file has, is an IP, Date Stamp, What they downloaded, and what protocol they were using. what I want to be able to do , is specify a date in delphi, and it read this log file, skip down to the specified date, and post all information reguarding any activity during that time/date.

So, is there anyway that I can do this? An example of a log file I have would be :

10.0.0.1 - - [14/Jun/2000:13:48:10 -0700] "GET encoder/bob.rm
RTSP/1.0" 200 146835 [WinNT_4.0_6.0.6.94_play32_RN6C_en-US_686]
[d0000cb00-000-00d0-001-0001000f0be0]

any/all help would be greately appreciated..... thanks again

-Jonathon Hibbard
Intermd Delphi Warrior lol
Report
Re: How can I pull info from a Log file, and post it in Delphi? Posted by zibadian on 3 Jul 2002 at 4:07 PM
: Hey all, I have a small question. What i'm wanting to do, is probably pretty simple, but I'm truthfully lost as I'm merely a newbie delphi boy. Don't get me wrong though, I know enough about delphi to make master/detail reports, but when it comes to interacting with files, reading a line, and then posting what is found, heh, i'm kinda at a loss..
:
: So, here is my problem. I have a small network setup at my house, that I use for sharing files. When someone accesses my network, what they are doing is logged into a log file ( let's call it bob.log ). Now, when I need to search for a specific date to see what joe henry was doing on january 28, 2002, I am gonnna have to go through hundreds of different dates and happenings before I finally come across the line that has the date that i need to see.
:
: What the file has, is an IP, Date Stamp, What they downloaded, and what protocol they were using. what I want to be able to do , is specify a date in delphi, and it read this log file, skip down to the specified date, and post all information reguarding any activity during that time/date.
:
: So, is there anyway that I can do this? An example of a log file I have would be :
:
: 10.0.0.1 - - [14/Jun/2000:13:48:10 -0700] "GET encoder/bob.rm
: RTSP/1.0" 200 146835 [WinNT_4.0_6.0.6.94_play32_RN6C_en-US_686]
: [d0000cb00-000-00d0-001-0001000f0be0]
:
: any/all help would be greately appreciated..... thanks again
:
: -Jonathon Hibbard
: Intermd Delphi Warrior lol
:
The easiest way to search the log is to encode the searchdate the same way as the date in the log, thus for example 01/Jul/2002. Then you could use Pos() to see if the date was on a certain line in the log. If it is, then show the entire log line.
Another way to do this is to read the log, then decode it into certain parts (IP, date, operation, protocol, etc.). Then compare this date to the search date. The decoding part of this will be the most difficult, but it will give you more flexibility in searching for specific log-records.
Report
Try this. Posted by Amokrun on 5 Jul 2002 at 3:42 AM
: 10.0.0.1 - - [14/Jun/2000:13:48:10 -0700] "GET encoder/bob.rm
: RTSP/1.0" 200 146835 [WinNT_4.0_6.0.6.94_play32_RN6C_en-US_686]
: [d0000cb00-000-00d0-001-0001000f0be0]

Since I'm unfamiliar with that specific format, this is just general guideline. Lets assume that you have log file in following (simple) format:

Name:Filename:Date

Now, I would make a simple data type that holds those 3 properties. Then read first record, parse it and save so that each property goes into right field. I guess data type would look around this:

Name: String
Filename: String;
Date : TDate

Read one line into temporary string, then read until you get to first ":". Then do same for filename, and finally read the date and parse it into Delphi format (if it is not so already). Now, make list of these types and proceed to read every item in that log list. This way you get a data type that contains all the information.

When you finally have it all in a list, just go through certain field. Assume that you need certain file. Just go from record 0 to length - 1 and you got it. Compare the property to the one you are looking for. This way, you can find any specific detail. It's not fast if your list is insanely long (then again, download list hopefully doesn't become long).

For the record you are looking at, first separate all fields from it. Without any details, these are my assumptions:

{IP} - - [{Day}/{Month}/{Year}:{hour}:{min}:{sec} -{somenumber}] "{HTML function} {filename}

Now, you simply need a slightly more complicated type:

TLogEntry = Record
IP : String; // Unless you want to make IP type of course.
Date : TDateTime; // Lets just forget about those seconds for a while.
Req_Type : String; // If you wish to store GET/POST/etc.
FileName : String; // For the complete file/path.
End;

Then just make a function that parses the information correctly. It's fairly simple, just see what information is where and use the [] and other special characters to determine where each part ends.

When you have it done, just make array of those records. When searching for specific entry, simply make a for loop from 0 to Length - 1 of that array and search for specific field, like

If (LogEntry[x].IP = "123.123.123.123") then....

Hopefully that helps. Of course, you can simply try to Pos() the date. However, I wouldn't suggest doing that, as you could simply find parts of the filename or anything like that which is hardly the information you were looking at. If you are simply doing manual program where you just click until you find it, go ahead and use Pos(). However, if you want to make it automatic (and so that you can trust it), parse the information for real.

So, it comes down to how good program you want. But, 1 hour spent in development is 100 hours gained when you use it.
Report
Re: How can I pull info from a Log file, and post it in Delphi? Posted by FreakboY on 12 Jul 2002 at 11:07 PM
Hello everybody! FreakboY is online again!

i was wondering if you got an anwser to
your question Mr. Jonathon Hibbard...
if you still need help... email me!

i'm bored, and i have like 3-5 months
that i don't open Delphi... not even
to remember old times! laters....



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.