Forum OpenACS Development: Response to aolserver-errors

Posted by Andrew Piskorski on
David, does your code handle the case where you're giving a max number of bytes to read from the server (error) log, but the log has been rolled over since the last time we've parsed it, so in fact it's a whole new file?

I don't think it does. I'm not really sure what the script does in that case, either.

Anyway, probably 99% of the time if the log has rolled it will be smaller than before. But that's not entirely certain. Is there any way to directly detect the fact that the log has rolled?

Here's a new code snippet with what I think is a partial solution to this log rolling issue:

if { $num_bytes > 0 } {
   set log_file_size [file size $log_file]
   set sizediff [expr {$log_file_size - $lastread}]

   # If the log has been rolled, presumably it will now be smaller
   # in size than it was last time.  So in that case, always read
   # from the beginning of the file.
   # TODO: But, it isn't GUARANTEED that it will always be smaller.
   # Is there any other way for us to detect if the log has been
   # rolled or otherwise fooled with?,
   # 2002/04/09 13:13 EDT

   if { $sizediff < 0 } {
      set lastread 0
      set sizediff [expr {$log_file_size - $lastread}]

   if { $sizediff > $num_bytes } {
      set lastread [expr {$log_file_size - $num_bytes}]

      append output "Log file grew by [expr {round(100.0 * [expr {$sizediff / 1024.0 / 1024.0}]) / 100.0}] megabytes.
Reporting on the last $num_bytes bytes of log.