本文整理汇总了Python中pygtail.Pygtail.next方法的典型用法代码示例。如果您正苦于以下问题:Python Pygtail.next方法的具体用法?Python Pygtail.next怎么用?Python Pygtail.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygtail.Pygtail
的用法示例。
在下文中一共展示了Pygtail.next方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FileFollower
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import next [as 别名]
class FileFollower():
'''
Use pygtail to keep track of EOF and rotated files, catch exceptions to
make things more seamless
'''
def __init__(self, path):
self.path = path
self.pygtail = None
self.last_inode = 0
def next(self):
line = ''
curr_inode = 0
if self.pygtail is None:
try:
# remove last offset file if the log file is different
# PygTail's inode detection doesn't work in certain cases
curr_inode = os.stat(self.path).st_ino
if self.last_inode != curr_inode:
os.unlink(self.path + '.offset')
self.last_inode = curr_inode
log.debug('deleted offset file, inode difference')
except Exception as e:
log.info('inode checking failed (not terminal): %s' % e)
self.pygtail = Pygtail(self.path)
try:
line = self.pygtail.next()
except StopIteration as si:
# Need to get a new instance of pygtail after this incase the inode
# has changed
self.pygtail = None
return False
return line
示例2: is_erased
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import next [as 别名]
if not os.path.exists(".offset"):
os.makedirs(".offset")
try:
if is_erased(file_name):
# forget about saved offset
# delete offset file
# print "remove file" # test point
os.remove(OFFSET_FILE)
except IOError:
# Error occur when first time run
pass
try:
pyg = Pygtail(file_name, OFFSET_FILE)
first_line = pyg.next()
# get log format and log type
log_type, log_format = parser.detect_log_type(first_line)
for line in Pygtail(file_name, OFFSET_FILE):
# print line # test point
error_info = parser.parse_log(line, log_type, log_format)
status_code = error_info['status_code']
if status_code == 502 or status_code == 503:
client.capture(
"raven.events.Message",
message=log_type + " " + str(status_code),
extra=error_info,
date=error_info['time']
)