def test_read_new_lines(self): tail = FileTail(filename=self.test_log) # write messages and read them for i in xrange(10): line = "this is %s line" % i self.write_log(line) new_lines = tail.readlines() assert_that(new_lines, has_length(1)) assert_that(new_lines.pop(), equal_to(line))
def test_cache_offset(self): tail = FileTail(filename=self.test_log) self.write_log('something') tail.readlines() old_offset = tail._offset # del tail object del tail # create new tail = FileTail(filename=self.test_log) assert_that(tail._offset, equal_to(old_offset))
def test_rotate(self): tail = FileTail(filename=self.test_log) # rotate it os.rename(self.test_log, self.test_log_rotated) # write something in a new one self.write_log("from a new file") # read tail and get two lines new_lines = tail.readlines() assert_that(new_lines, has_length(1)) assert_that(new_lines, equal_to(['from a new file']))
def test_no_new_lines(self): # check one new line tail = FileTail(filename=self.test_log) self.write_log('something') new_lines = tail.readlines() assert_that(new_lines, has_length(1)) # check no new lines new_lines = tail.readlines() assert_that(new_lines, has_length(0)) # and check again one new line tail = FileTail(filename=self.test_log) self.write_log('something') new_lines = tail.readlines() assert_that(new_lines, has_length(1))
def __init__(self, filename=None, level=None, log_format=None, tail=None, **kwargs): super(NginxErrorLogsCollector, self).__init__(**kwargs) self.filename = filename self.level = level self.parser = NginxErrorLogParser() self.tail = tail if tail is not None else FileTail(filename)
def __init__(self, filename=None, log_format=None, tail=None, **kwargs): super(NginxAccessLogsCollector, self).__init__(**kwargs) self.filename = filename self.parser = NginxAccessLogParser(log_format) self.tail = tail if tail is not None else FileTail(filename) self.filters = [] # skip empty filters and filters for other log file for log_filter in self.object.filters: if log_filter.empty: continue if log_filter.filename and log_filter.filename != self.filename: continue self.filters.append(log_filter)