mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Allow to display part of log specified with path
This commit is contained in:
parent
d17193b404
commit
1b62e9425d
2 changed files with 17 additions and 9 deletions
|
@ -1625,7 +1625,12 @@ log:
|
||||||
### log_display()
|
### log_display()
|
||||||
display:
|
display:
|
||||||
action_help: Display a log content
|
action_help: Display a log content
|
||||||
api: GET /logs/<file_name_list>
|
api: GET /logs/<file_name>
|
||||||
arguments:
|
arguments:
|
||||||
file_name:
|
file_name:
|
||||||
help: Log filenames for which to display the content
|
help: Log filename which to display the content
|
||||||
|
-n:
|
||||||
|
full: --number
|
||||||
|
help: Number of lines to display
|
||||||
|
default: 50
|
||||||
|
type: int
|
||||||
|
|
|
@ -98,18 +98,21 @@ def log_display(file_name, number=50):
|
||||||
else:
|
else:
|
||||||
base_filename = file_name
|
base_filename = file_name
|
||||||
|
|
||||||
md_filename = base_filename + METADATA_FILE_EXT
|
base_path = base_filename
|
||||||
md_path = os.path.join(OPERATIONS_PATH, md_filename)
|
if not base_filename.startswith('/'):
|
||||||
log_filename = base_filename + LOG_FILE_EXT
|
base_path = os.path.join(OPERATIONS_PATH, base_filename)
|
||||||
log_path = os.path.join(OPERATIONS_PATH, log_filename)
|
|
||||||
|
md_path = base_path + METADATA_FILE_EXT
|
||||||
|
log_path = base_path + LOG_FILE_EXT
|
||||||
operation = base_filename.split("-")
|
operation = base_filename.split("-")
|
||||||
|
|
||||||
if not os.path.exists(md_path) and not os.path.exists(log_path):
|
if not os.path.exists(md_path) and not os.path.exists(log_path):
|
||||||
raise MoulinetteError(errno.EINVAL,
|
raise MoulinetteError(errno.EINVAL,
|
||||||
m18n.n('log_does_exists', log=file_name))
|
m18n.n('log_does_exists', log=file_name))
|
||||||
infos = {}
|
infos = {}
|
||||||
infos['description'] = m18n.n("log_" + operation[2], *operation[3:]),
|
if not base_filename.startswith('/'):
|
||||||
infos['name'] = base_filename
|
infos['description'] = m18n.n("log_" + operation[2], *operation[3:]),
|
||||||
|
infos['name'] = base_filename
|
||||||
|
|
||||||
if os.path.exists(md_path):
|
if os.path.exists(md_path):
|
||||||
with open(md_path, "r") as md_file:
|
with open(md_path, "r") as md_file:
|
||||||
|
@ -125,7 +128,7 @@ def log_display(file_name, number=50):
|
||||||
if os.path.exists(log_path):
|
if os.path.exists(log_path):
|
||||||
from yunohost.service import _tail
|
from yunohost.service import _tail
|
||||||
logs = _tail(log_path, int(number))
|
logs = _tail(log_path, int(number))
|
||||||
logs = [{"datetime": x.split(": ", 1)[0].replace("_", " "), "line": x.split(": ", 1)[1]} for x in logs if x]
|
#logs = [{"datetime": x.split(": ", 1)[0].replace("_", " "), "line": x.split(": ", 1)[1]} for x in logs if x]
|
||||||
infos['log_path'] = log_path
|
infos['log_path'] = log_path
|
||||||
infos['logs'] = logs
|
infos['logs'] = logs
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue