diff --git a/src/yunohost/log.py b/src/yunohost/log.py index 2b5f91e1b..875d4e49d 100644 --- a/src/yunohost/log.py +++ b/src/yunohost/log.py @@ -136,6 +136,26 @@ def log_display(path, number=None, share=False, filter_irrelevant=False): share """ + if filter_irrelevant: + filters = [ + r"set [+-]x$", + r"set [+-]o xtrace$", + r"local \w+$", + r"local legacy_args=.*$", + r".*Helper used in legacy mode.*", + r"args_array=.*$", + r"local -A args_array$", + r"ynh_handle_getopts_args", + r"ynh_script_progression" + ] + else: + filters = [] + + def _filter_lines(lines, filters=[]): + + filters = [re.compile(f) for f in filters] + return [l for l in lines if not any(f.search(l.strip()) for f in filters)] + # Normalize log/metadata paths and filenames abs_path = path log_path = None @@ -174,7 +194,8 @@ def log_display(path, number=None, share=False, filter_irrelevant=False): content += read_file(md_path) content += "\n============\n\n" if os.path.exists(log_path): - content += read_file(log_path) + actual_log = read_file(log_path) + content += "\n".join(_filter_lines(actual_log.split("\n"), filters)) url = yunopaste(content) @@ -203,27 +224,12 @@ def log_display(path, number=None, share=False, filter_irrelevant=False): # Display logs if exist if os.path.exists(log_path): - - if filter_irrelevant: - filters = [ - r"set [+-]x$", - r"set [+-]o xtrace$", - r"local \w+$", - r"local legacy_args=.*$", - r".*Helper used in legacy mode.*", - r"args_array=.*$", - r"local -A args_array$", - r"ynh_handle_getopts_args", - r"ynh_script_progression" - ] - else: - filters = [] - from yunohost.service import _tail if number: - logs = _tail(log_path, int(number), filters=filters) + logs = _tail(log_path, int(number)) else: logs = read_file(log_path) + logs = _filter_lines(logs, filters) infos['log_path'] = log_path infos['logs'] = logs diff --git a/src/yunohost/service.py b/src/yunohost/service.py index faaf70cdc..278cea0a4 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -639,7 +639,7 @@ def _save_services(services): raise -def _tail(file, n, filters=[]): +def _tail(file, n): """ Reads a n lines from f with an offset of offset lines. The return value is a tuple in the form ``(lines, has_more)`` where `has_more` is @@ -650,8 +650,6 @@ def _tail(file, n, filters=[]): avg_line_length = 74 to_read = n - if filters: - filters = [re.compile(f) for f in filters] try: if file.endswith(".gz"): @@ -673,9 +671,6 @@ def _tail(file, n, filters=[]): pos = f.tell() lines = f.read().splitlines() - for filter_ in filters: - lines = [l for l in lines if not filter_.search(l)] - if len(lines) >= to_read: return lines[-to_read:]