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
|
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
|
# Normalize log/metadata paths and filenames
|
||||||
abs_path = path
|
abs_path = path
|
||||||
log_path = None
|
log_path = None
|
||||||
|
@ -174,7 +194,8 @@ def log_display(path, number=None, share=False, filter_irrelevant=False):
|
||||||
content += read_file(md_path)
|
content += read_file(md_path)
|
||||||
content += "\n============\n\n"
|
content += "\n============\n\n"
|
||||||
if os.path.exists(log_path):
|
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)
|
url = yunopaste(content)
|
||||||
|
|
||||||
|
@ -203,27 +224,12 @@ def log_display(path, number=None, share=False, filter_irrelevant=False):
|
||||||
|
|
||||||
# Display logs if exist
|
# Display logs if exist
|
||||||
if os.path.exists(log_path):
|
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
|
from yunohost.service import _tail
|
||||||
if number:
|
if number:
|
||||||
logs = _tail(log_path, int(number), filters=filters)
|
logs = _tail(log_path, int(number))
|
||||||
else:
|
else:
|
||||||
logs = read_file(log_path)
|
logs = read_file(log_path)
|
||||||
|
logs = _filter_lines(logs, filters)
|
||||||
infos['log_path'] = log_path
|
infos['log_path'] = log_path
|
||||||
infos['logs'] = logs
|
infos['logs'] = logs
|
||||||
|
|
||||||
|
|
|
@ -639,7 +639,7 @@ def _save_services(services):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def _tail(file, n, filters=[]):
|
def _tail(file, n):
|
||||||
"""
|
"""
|
||||||
Reads a n lines from f with an offset of offset lines. The return
|
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
|
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
|
avg_line_length = 74
|
||||||
to_read = n
|
to_read = n
|
||||||
|
|
||||||
if filters:
|
|
||||||
filters = [re.compile(f) for f in filters]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if file.endswith(".gz"):
|
if file.endswith(".gz"):
|
||||||
|
@ -673,9 +671,6 @@ def _tail(file, n, filters=[]):
|
||||||
pos = f.tell()
|
pos = f.tell()
|
||||||
lines = f.read().splitlines()
|
lines = f.read().splitlines()
|
||||||
|
|
||||||
for filter_ in filters:
|
|
||||||
lines = [l for l in lines if not filter_.search(l)]
|
|
||||||
|
|
||||||
if len(lines) >= to_read:
|
if len(lines) >= to_read:
|
||||||
return lines[-to_read:]
|
return lines[-to_read:]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue