You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
I have been given the task of monitoring a log file for certain text which gets written to every couple of minutes. Is there any way to use PB/CC to "follow" the text file? Or is there another approach I can use?
User to user discussions about the PB/Win (formerly PB/DLL) product line. Discussion topics include PowerBASIC Forms, PowerGEN and PowerTree for Windows.
Another application is appending data to the text file and I need to search for the presence of certain text and then generate an e-mail with the most recent certain text.
- Montior the directory where the log file is.
- When you get notified of a change in that directory, check to see if it's YOUR file which has changed
- If it has changed, do whatever it is you need to do.
The demo link I supplied will get you started. The rest is up to you. (Yes, there ARE demos of sending email here, too).
I'd have to reread the text file and it would send e-mails for the text that was already processed
Gee, I wonder if you could keep track of how big the file was at the time you sent the email, then get the new size when you've been notified of a change, then read only the data which has been added to the fule since the last time you sent email and only send new emails based on that new data?
Nah, that would be too good to be true that it's that simple.
Keeping track of the file size did come to mind...
In my particular case, the file gets archived after reaching 50MB and then a new file is created - same file name. I suppose I could GET x amount of characters up to the last file size (unless the new file size is < last file size) and the LINE INPUT the remainder to process. A sort of poor man's "tail -f".
'tail' might be useful, except ain't no such thing as 'tail' in (standard) command shell, so you'll have to do it yourself.
BTW, you WILL get a notification when the file is archived as long as you tell FindFirstChangeNotification you want to be notified on deletes. Also when a file is added.
I don't know how this "archiving" works exactly but I do know you can set up FindFirstNotification to tell you everything you could possibly want to know about what is happening in that directory.
BTW, it sounds like this is not the optimal design... why not have your program handle the archiving? That way it will never be archived unless all the required emails have been sent from it.
Depending on how this archiving is done now... it sounds like archiving could start while YOU are in the file and now your results are going to be 'pot luck.'
Better IMNSHO ONE program should control "report changes, archive when necessary."
Yes, that would be t!ts if my program could control the archiving. I've asked my boss to call the vendor of the app that writes to this log file to see what would happen if the vendor's app did not find the log file (which would mean that I have archived it with my program). As long as no other subprogram of theirs uses the data from that logfile then it seems logical that if I rename trace.txt to traceYYYYMMDDHHMMSS.txt their app would just create a new trace.txt and proceed to append to that until my program runs again and does the archiving and processing on the archived copy instead of a live file.
Well, you have other issues to discuss with that vendor...
For example, if that vendor leaves the file OPEN while his program is running and does so in exclusive mode... you won't be able to even read that file. (I assume you have already tested this).
(BTW if the vendor never closes the file after writing, you won't get notifications from Find[First|Next]ChangeNotification because the directory is not updated until the file is closed).
Or, what will happen if if that vendor's program suddenly finds the file it wants to write to unavailable not because it's gone (archived), but because it is in use? (You are reading it but your sharing strategy is not consistent with that vendor's program.)
Or, does that vendor offer an "exit" or "hook" point where you could have your program "do its email thing" without stepping on that vendor's program logic vis-a-vis his logging operations? This would eliminate your need to monitor anything.
All in all, I have never been a fan of trying to inject my code into other applications which were never designed to support that kind of thing. I will look for another "how" to accomplish my goal... which brings us to....
What is really the goal here? "Monitor the log file for changes and send email based on new data therein" sure sounds like a "how".... but what is the real "what?" There may be a better way...a better way your vendor may be able to suggest *if* you ask him directly.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment