Skip to content

Commit

Permalink
Add support for failing test proposed in #42
Browse files Browse the repository at this point in the history
  • Loading branch information
bgreenlee committed Oct 30, 2022
1 parent f1ae186 commit 2839302
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pygtail/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def __init__(self, filename, offset_file=None, paranoid=False, copytruncate=True
# might have been rotated.
# Look for the rotated file and process that if we find it.
self.rotated_logfile = self._determine_rotated_logfile()
# If copytruncate is enabled and we can't find the rotated logfile, all we can do is reset.
if self.copytruncate and self.rotated_logfile is None:
sys.stderr.write("[pygtail] [WARN] log file was rotated to unknown location. Resetting.\n")
self.offset = 0
self.update_offset_file()


def __del__(self):
if self._filehandle():
Expand Down
6 changes: 6 additions & 0 deletions pygtail/test/test_pygtail.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,15 @@ def test_renamecreate_unknown_rotated_name(self):
self.append(new_lines[0])
self.append(new_lines[1])
# reopen using Pytgail
sys.stderr = captured = io.BytesIO() if PY2 else io.StringIO()
pygtail = Pygtail(self.logfile.name)
captured_value = captured.getvalue()
sys.stderr = sys.__stderr__
assert_class = self.assertRegex if sys.version_info >= (3, 1) else self.assertRegexpMatches
assert_class(captured_value, r".*?\bWARN\b.*?\bResetting\b.*")
self.assertEqual(pygtail.read(), ''.join(new_lines))


def test_full_lines(self):
"""
Tests lines are logged only when they have a new line at the end. This is useful to ensure that log lines
Expand Down

0 comments on commit 2839302

Please sign in to comment.