mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #960 from YunoHost/smarter-debug-logs
Try to show smarter / more useful logs by filtering irrelevant lines like set +x etc
This commit is contained in:
commit
a7d52af77e
5 changed files with 53 additions and 4 deletions
|
@ -1659,6 +1659,10 @@ log:
|
|||
--share:
|
||||
help: Share the full log using yunopaste
|
||||
action: store_true
|
||||
-i:
|
||||
full: --filter-irrelevant
|
||||
help: Do not show some lines deemed not relevant (like set +x or helper argument parsing)
|
||||
action: store_true
|
||||
|
||||
|
||||
#############################
|
||||
|
|
|
@ -35,7 +35,10 @@ ynh_exit_properly () {
|
|||
ynh_clean_setup # Call the function to do specific cleaning for the app.
|
||||
fi
|
||||
|
||||
ynh_die # Exit with error status
|
||||
# Exit with error status
|
||||
# We don't call ynh_die basically to avoid unecessary 10-ish
|
||||
# debug lines about parsing args and stuff just to exit 1..
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Exits if an error occurs during the execution of the script.
|
||||
|
|
|
@ -914,6 +914,20 @@ def dump_app_log_extract_for_debugging(operation_logger):
|
|||
with open(operation_logger.log_path, "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
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"
|
||||
]
|
||||
|
||||
filters = [re.compile(f) for f in filters]
|
||||
|
||||
lines_to_display = []
|
||||
for line in lines:
|
||||
|
||||
|
@ -924,6 +938,10 @@ def dump_app_log_extract_for_debugging(operation_logger):
|
|||
# 2019-10-19 16:10:27,611: DEBUG - + mysql -u piwigo --password=********** -B piwigo
|
||||
# And we just want the part starting by "DEBUG - "
|
||||
line = line.strip().split(": ", 1)[1]
|
||||
|
||||
if any(filter_.search(line) for filter_ in filters):
|
||||
continue
|
||||
|
||||
lines_to_display.append(line)
|
||||
|
||||
if line.endswith("+ ynh_exit_properly") or " + ynh_die " in line:
|
||||
|
|
|
@ -122,7 +122,7 @@ def log_list(category=[], limit=None, with_details=False):
|
|||
return result
|
||||
|
||||
|
||||
def log_display(path, number=None, share=False):
|
||||
def log_display(path, number=None, share=False, filter_irrelevant=False):
|
||||
"""
|
||||
Display a log file enriched with metadata if any.
|
||||
|
||||
|
@ -202,9 +202,25 @@ def log_display(path, number=None, share=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))
|
||||
logs = _tail(log_path, int(number), filters=filters)
|
||||
else:
|
||||
logs = read_file(log_path)
|
||||
infos['log_path'] = log_path
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
Manage services
|
||||
"""
|
||||
|
||||
import re
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
|
@ -616,7 +618,7 @@ def _save_services(services):
|
|||
raise
|
||||
|
||||
|
||||
def _tail(file, n):
|
||||
def _tail(file, n, filters=[]):
|
||||
"""
|
||||
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
|
||||
|
@ -627,6 +629,9 @@ def _tail(file, n):
|
|||
avg_line_length = 74
|
||||
to_read = n
|
||||
|
||||
if filters:
|
||||
filters = [re.compile(f) for f in filters]
|
||||
|
||||
try:
|
||||
if file.endswith(".gz"):
|
||||
import gzip
|
||||
|
@ -647,6 +652,9 @@ def _tail(file, n):
|
|||
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