本文整理汇总了Python中pygtail.Pygtail.read方法的典型用法代码示例。如果您正苦于以下问题:Python Pygtail.read方法的具体用法?Python Pygtail.read怎么用?Python Pygtail.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygtail.Pygtail
的用法示例。
在下文中一共展示了Pygtail.read方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_subsequent_read_with_new_data
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_subsequent_read_with_new_data(self):
pygtail = Pygtail(self.logfile.name)
self.assertEqual(pygtail.read(), self.test_str)
new_lines = "4\n5\n"
self.append(new_lines)
new_pygtail = Pygtail(self.logfile.name)
self.assertEqual(new_pygtail.read(), new_lines)
示例2: test_logrotate_with_delay_compress
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_logrotate_with_delay_compress(self):
new_lines = ["4\n5\n", "6\n7\n"]
pygtail = Pygtail(self.logfile.name)
pygtail.read()
self.append(new_lines[0])
os.rename(self.logfile.name, "%s.1" % self.logfile.name)
self.append(new_lines[1])
pygtail = Pygtail(self.logfile.name)
self.assertEqual(pygtail.read(), ''.join(new_lines))
示例3: test_logrotate_without_close
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_logrotate_without_close(self):
new_lines = ["4\n5\n", "6\n7\n"]
pygtail = Pygtail(self.logfile.name)
pygtail.read()
self.append(new_lines[0])
# note it doesn't matter what filename the file gets rotated to
os.rename(self.logfile.name, "%s.somethingodd" % self.logfile.name)
self.append(new_lines[1])
self.assertEqual(pygtail.read(), ''.join(new_lines))
示例4: test_logrotate
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_logrotate(self):
new_lines = ["4\n5\n", "6\n7\n"]
pygtail = Pygtail(self.logfile.name)
pygtail.read()
self.append(new_lines[0])
os.rename(self.logfile.name, "%s.1" % self.logfile.name)
self.append(new_lines[1])
pygtail = Pygtail(self.logfile.name)
self.assertEquals(pygtail.read(), "".join(new_lines))
示例5: test_copytruncate_off_smaller_without_close
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_copytruncate_off_smaller_without_close(self):
new_lines = ["4\n5\n", "6\n7\n"]
pygtail = Pygtail(self.logfile.name, copytruncate=True)
pygtail.read()
self.append(new_lines[0])
read1 = pygtail.read()
self.copytruncate()
self.append(new_lines[1])
read2 = pygtail.read()
self.assertEqual([read1,read2], new_lines)
示例6: test_copytruncate_on_smaller
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_copytruncate_on_smaller(self):
self.test_readlines()
self.copytruncate()
new_lines = "4\n5\n"
self.append(new_lines)
pygtail = Pygtail(self.logfile.name, copytruncate=True)
self.assertEqual(pygtail.read(), new_lines)
示例7: _test_copytruncate_larger
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def _test_copytruncate_larger(self, onoff):
self.test_readlines()
self.copytruncate()
self.append(self.test_str)
new_lines = "4\n5\n"
self.append(new_lines)
pygtail = Pygtail(self.logfile.name, copytruncate=onoff)
self.assertEqual(pygtail.read(), new_lines)
示例8: test_copytruncate_off_smaller
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_copytruncate_off_smaller(self):
self.test_readlines()
self.copytruncate()
new_lines = "4\n5\n"
self.append(new_lines)
pygtail = Pygtail(self.logfile.name, copytruncate=False)
self.assertEqual(pygtail.read(), None)
self.assertRegexpMatches(sys.stderr.getvalue(), r".*?\bWARN\b.*?\bshrank\b.*")
示例9: test_logrotate_without_delay_compress
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_logrotate_without_delay_compress(self):
new_lines = ["4\n5\n", "6\n7\n"]
pygtail = Pygtail(self.logfile.name)
pygtail.read()
self.append(new_lines[0])
# put content to gzip file
gzip_handle = gzip.open("%s.1.gz" % self.logfile.name, 'wb')
with open(self.logfile.name, 'rb') as logfile:
gzip_handle.write(logfile.read())
gzip_handle.close()
with open(self.logfile.name, 'w'):
# truncate file
pass
self.append(new_lines[1])
pygtail = Pygtail(self.logfile.name)
self.assertEqual(pygtail.read(), ''.join(new_lines))
示例10: test_copytruncate_off_smaller
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_copytruncate_off_smaller(self):
self.test_readlines()
self.copytruncate()
new_lines = "4\n5\n"
self.append(new_lines)
sys.stderr = captured = io.BytesIO() if PY2 else io.StringIO()
pygtail = Pygtail(self.logfile.name, copytruncate=False)
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.*?\bshrank\b.*")
self.assertEqual(pygtail.read(), None)
示例11: on_modified
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def on_modified(self, event):
super(TailContentCollector, self).on_modified(event)
# what = 'directory' if event.is_directory else 'file'
# logging.info("Modified %s: %s", what, event.src_path)
# split_path = None
log_file = event.src_path.split("/")
# prepare offset file directory
if not os.path.exists(self.offset_dir):
os.makedirs(self.offset_dir)
offset_file = "%s/%s.os" % (self.offset_dir, log_file[-1])
# offset file must separate with monitor directory, and is local variable...
tailor = Pygtail(event.src_path, offset_file, paranoid=True)
appended = tailor.read()
if appended:
# must use gbk decoding...
decodelines = appended.decode("gbk")
# execute callback function...
self.onchange(event.src_path, decodelines)
else:
logging.info("empty content: %s", event.src_path)
示例12: test_subsequent_read_with_no_new_data
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_subsequent_read_with_no_new_data(self):
pygtail = Pygtail(self.logfile.name)
self.assertEqual(pygtail.read(), self.test_str)
self.assertEqual(pygtail.read(), None)
示例13: test_read
# 需要导入模块: from pygtail import Pygtail [as 别名]
# 或者: from pygtail.Pygtail import read [as 别名]
def test_read(self):
pygtail = Pygtail(self.logfile.name)
self.assertEqual(pygtail.read(), self.test_str)