[fix] check if log exists before tailing to avoid errors

This commit is contained in:
Laurent Peuch 2018-05-31 09:32:29 +02:00
parent 911a4ec507
commit 3a6f3c3732

View file

@ -298,7 +298,7 @@ def service_log(name, number=50):
for log_path in log_list:
# log is a file, read it
if not os.path.isdir(log_path):
result[log_path] = _tail(log_path, int(number))
result[log_path] = _tail(log_path, int(number)) if os.path.exists(log_path) else []
continue
for log_file in os.listdir(log_path):
@ -310,7 +310,7 @@ def service_log(name, number=50):
if not log_file.endswith(".log"):
continue
result[log_file_path] = _tail(log_file_path, int(number))
result[log_file_path] = _tail(log_file_path, int(number)) if os.path.exists(log_file_path) else []
return result