Logfile roll-over

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Logfile roll-over

Marc Dirix-2
Hello,

Pike8.0 under windows 10.

I have a script that follows a logfile to detect a certain message.
Principially I'm using Stdio.FILE->gets(). This works well, until at some point the program decides to roll-over the logfile. 

I have not tested it, but I suppose the Stdio.FILE object just keeps to old renamed file open.

Is there an easy way to detect the moving of the logfile from the Stdio.FILE object?

Best regards,
Marc Dirix
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logfile roll-over

Lance Dillon-2
What some programs do is not keep the file open, but open it new each time, keeping a pointer to where it was last.  If you are unable to seek that far, it means the log file has been restarted, and so seek back to the beginning and start over.



On Thursday, April 20, 2017 7:14 AM, Marc dirix <[hidden email]> wrote:


Hello,

Pike8.0 under windows 10.

I have a script that follows a logfile to detect a certain message.
Principially I'm using Stdio.FILE->gets(). This works well, until at some point the program decides to roll-over the logfile. 

I have not tested it, but I suppose the Stdio.FILE object just keeps to old renamed file open.

Is there an easy way to detect the moving of the logfile from the Stdio.FILE object?

Best regards,
Marc Dirix


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logfile roll-over

Stephen R. van den Berg
Lance Dillon wrote:
>What some programs do is not keep the file open, but open it new each time, keeping a pointer to where it was last.?? If you are unable to seek that far, it means the log file has been restarted, and so seek back to the beginning and start over.

What tail --follow does (I think), is keep the file open, but
if the file does not show any new content after
a certain timeout it periodically stats() the file and checks
if the mtime of the file is higher than the last time that it
received something through the open filedescriptor.  If yes,
it then closes and reopens the file.
--
Stephen.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Logfile roll-over

Marc Dirix-2
Ok thanks. I think that is a good solution.

/M

Op vr 21 apr. 2017 om 11:09 schreef Stephen R. van den Berg <[hidden email]>:
Lance Dillon wrote:
>What some programs do is not keep the file open, but open it new each time, keeping a pointer to where it was last.?? If you are unable to seek that far, it means the log file has been restarted, and so seek back to the beginning and start over.

What tail --follow does (I think), is keep the file open, but
if the file does not show any new content after
a certain timeout it periodically stats() the file and checks
if the mtime of the file is higher than the last time that it
received something through the open filedescriptor.  If yes,
it then closes and reopens the file.
--
Stephen.

Loading...