Announcement

Collapse
No announcement yet.

How would I "follow" a text log file?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How would I "follow" a text log file?

    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?

    Thanks!
    Roger

  • #2
    Are you saying that "another" application is writing the logfile? Or is your PBCC app handling that?
    Rick Angell

    Comment


    • #3
      >Is there any way to use PB/CC to "follow" the text file?

      You might want to jump into this current thread in another forum....

      http://www.powerbasic.com/support/pb...ad.php?t=36483

      (The answer is: Yes, you CAN do that).

      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Yes, another app is appending.

        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.

        Thanks!
        Roger

        Comment


        • #5
          In a nutshelll what yoiu have to do is...

          - 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).

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Unfortunately,

            I'd have to reread the text file and it would send e-mails for the text that was already processed.

            Comment


            • #7
              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.

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                >I have been given the task of monitoring a log file for

                You could always contact my office for a quotation.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  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".

                  Comment


                  • #10
                    '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."

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Great idea!

                      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.

                      Comment


                      • #12
                        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.

                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment

                        Working...
                        X