pygtail
pygtail copied to clipboard
Add support for externalizing `rotated_filename_patterns` and comparator
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.
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!
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.
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
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.