pygtail icon indicating copy to clipboard operation
pygtail copied to clipboard

Add support for externalizing `rotated_filename_patterns` and comparator

Open bobtiernay-okta opened this issue 7 years ago • 4 comments

Currently rotated_filename_patterns is hard coded into the library. It should be possible to externalize this so that it can be used with other schemes which are not logrotate or savelog based. This requires that the sorting logic also be externalized for general usage.

bobtiernay-okta avatar Sep 14 '17 20:09 bobtiernay-okta

Let me know if you agree with the change and if you have any design thoughts. I'll be happy to open a PR. Thanks!

bobtiernay-okta avatar Sep 16 '17 15:09 bobtiernay-okta

Any update on this one? We also have the same problem because we use customized log naming scheme.

The worst part is that when _determine_rotated_logfile cannot find the old log file, pygtail leave self._offset as old offset, and it will use old offset against new log file, which will not work because old offset is always greater than new offset. The pygtail will stop.

czchen avatar Mar 14 '18 07:03 czchen

I think having a config file would be a good idea, especially as the list of config flags grows. I don't have time right now to work on this, but I would certainly entertain a PR!

bgreenlee avatar Mar 14 '18 14:03 bgreenlee

@bgreenlee

I don't quite understand the logic behind the following code in _check_rotated_filename_candidates. Could you help to explain it?

        # savelog(8)
        candidate = "%s.0" % self.filename
        if (exists(candidate) and exists("%s.1.gz" % self.filename) and
            (stat(candidate).st_mtime > stat("%s.1.gz" % self.filename).st_mtime)):
            return candidate

My plan is to add an arg rotated_filename_patterns for caller to determine rotated file patterns in priority order, and the default value of rotated_filename_patterns is the same as pattern in _check_rotated_filename_candidates right now.

czchen avatar Mar 14 '18 15:03 czchen