Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use tailhead instead of tailer so as to handle rotating logs #29

Merged
merged 5 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
raven>=3.3.2
tailer>=0.3
tailhead
18 changes: 10 additions & 8 deletions sentrylogs/parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Log file parsers provided by Sentry Logs
"""
import tailer # same functionality as UNIX tail in python
import tailhead # same functionality as UNIX tail in python

from ..helpers import send_message

Expand All @@ -27,22 +27,24 @@ def follow_tail(self):
Read (tail and follow) the log file, parse entries and send messages
to Sentry using Raven.
"""

try:
logfile = open(self.filepath)
follower = tailhead.follow_path(self.filepath)
except (FileNotFoundError, PermissionError) as err:
raise SystemExit("Error: Can't read logfile %s (%s)" %
(self.filepath, err))

for line in tailer.follow(logfile):
for line in follower:
self.message = None
self.params = None
self.site = None

self.parse(line)
send_message(self.message,
self.params,
self.site,
self.logger)
if line is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simply

if line:

... which is pythonic. Also, an empty line wouldn't need to be parsed, right?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think an empty line could be important to parse. Empty lines are often used as separators. Not used that way for nginx, but this part of the code is not nginx specific.

self.parse(line)
send_message(self.message,
self.params,
self.site,
self.logger)

def parse(self, line):
"""
Expand Down