mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Tweak log filter logic to be able to apply it during --share as well
This commit is contained in:
parent
d615546b18
commit
38704cbae4
2 changed files with 25 additions and 24 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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:]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue