limit logs to a number

This commit is contained in:
Pierre Bourré 2019-01-22 01:50:16 +01:00
parent ddbe11035d
commit a2935dc44b

View file

@ -376,7 +376,7 @@ def service_log(name, number=50):
for log_path in log_list: for log_path in log_list:
# log is a file, read it # log is a file, read it
if log_path == "systemd": if log_path == "systemd":
result[log_path] = _get_journalctl_logs(name) result[log_path] = _get_journalctl_logs(name, int(number))
continue continue
elif not os.path.isdir(log_path): elif not os.path.isdir(log_path):
result[log_path] = _tail(log_path, int(number)) if os.path.exists(log_path) else [] result[log_path] = _tail(log_path, int(number)) if os.path.exists(log_path) else []
@ -1050,9 +1050,9 @@ def manually_modified_files():
return output return output
def _get_journalctl_logs(service): def _get_journalctl_logs(service, number="all"):
try: try:
return subprocess.check_output("journalctl -xn -u %s" % service, shell=True) return subprocess.check_output("journalctl -xn -u {0} -n{1}".format(service, number), shell=True)
except: except:
import traceback import traceback
return "error while get services logs from journalctl:\n%s" % traceback.format_exc() return "error while get services logs from journalctl:\n%s" % traceback.format_exc()