def test_filter_logline(p): # Given logline = LogLine.from_line(p['line']) # When actual = sut.filter_logline(logline, min_level=p.get('min_level'), thread_name=p.get('thread_name'), search_query=p.get('search_query')) # Then assert p['expected'] == actual
def data_generator(): """Read log lines based on the specified criteria.""" start = arg_limit * (arg_page - 1) + 1 reader_kwargs = dict( modification_time=modification_time, start_index=start, max_lines=arg_limit * arg_page, predicate=lambda li: filter_logline(li, min_level=min_level, thread_name=thread_name, search_query=search_query), ) for line in read_loglines(**reader_kwargs): yield line.to_json() if not raw_text else text_type(line)
def viewlog(self, min_level=logging.INFO, log_filter=None, log_search=None, max_lines=1000, log_period='one_day', text_view=None, **kwargs): """View the log given the specified filters.""" # @TODO: Replace index with this or merge it so ?search=true or ?query={queryString} enables this "view" min_level = int(min_level) log_filter = log_filter if log_filter in log_name_filters else None t = PageTemplate(rh=self, filename='viewlogs.mako') period = log_periods.get(log_period) modification_time = datetime.now() - period if period else None data = [ line for line in read_loglines( modification_time=modification_time, formatter=text_type, max_lines=max_lines, predicate=lambda l: filter_logline(l, min_level=min_level, thread_name=thread_names. get(log_filter, log_filter), search_query=log_search)) ] if not text_view: return t.render(topmenu='system', log_lines='\n'.join( [html_escape(line) for line in data]), min_level=min_level, log_name_filters=log_name_filters, log_filter=log_filter, log_search=log_search, log_period=log_period, controller='errorlogs', action='viewlogs') else: return '<br/>'.join([html_escape(line) for line in data])
def viewlog(self, min_level=logging.INFO, log_filter=None, log_search=None, max_lines=1000, log_period='one_day', text_view=None, **kwargs): """View the log given the specified filters.""" # @TODO: Replace index with this or merge it so ?search=true or ?query={queryString} enables this "view" min_level = int(min_level) log_filter = log_filter if log_filter in log_name_filters else None t = PageTemplate(rh=self, filename='viewlogs.mako') period = log_periods.get(log_period) modification_time = datetime.now() - period if period else None data = (html_escape(line) for line in read_loglines(modification_time=modification_time, formatter=text_type, max_lines=max_lines, predicate=lambda l: filter_logline(l, min_level=min_level, thread_name=thread_names.get(log_filter, log_filter), search_query=log_search))) if not text_view: return t.render(log_lines='\n'.join(data), min_level=min_level, log_name_filters=log_name_filters, log_filter=log_filter, log_search=log_search, log_period=log_period, controller='errorlogs', action='viewlogs') else: return '<br/>'.join(data)
def data_generator(): """Read log lines based on the specified criteria.""" start = arg_limit * (arg_page - 1) + 1 for l in read_loglines(start_index=start, max_lines=arg_limit * arg_page, predicate=lambda li: filter_logline(li, min_level=min_level)): yield l.to_json()