mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Get rid of unused complexity for other log categories ... it's been since 3.2 and we only have operations
This commit is contained in:
parent
d00421641c
commit
9a7bd77269
2 changed files with 39 additions and 58 deletions
|
@ -1631,9 +1631,6 @@ log:
|
||||||
action_help: List logs
|
action_help: List logs
|
||||||
api: GET /logs
|
api: GET /logs
|
||||||
arguments:
|
arguments:
|
||||||
category:
|
|
||||||
help: Log category to display (default operations), could be operation, history, package, system, access, service or app
|
|
||||||
nargs: "*"
|
|
||||||
-l:
|
-l:
|
||||||
full: --limit
|
full: --limit
|
||||||
help: Maximum number of logs
|
help: Maximum number of logs
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import yaml
|
import yaml
|
||||||
import collections
|
|
||||||
import glob
|
import glob
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
|
@ -43,8 +42,6 @@ from moulinette.utils.filesystem import read_file, read_yaml
|
||||||
|
|
||||||
CATEGORIES_PATH = '/var/log/yunohost/categories/'
|
CATEGORIES_PATH = '/var/log/yunohost/categories/'
|
||||||
OPERATIONS_PATH = '/var/log/yunohost/categories/operation/'
|
OPERATIONS_PATH = '/var/log/yunohost/categories/operation/'
|
||||||
#CATEGORIES = ['operation', 'history', 'package', 'system', 'access', 'service', 'app']
|
|
||||||
CATEGORIES = ['operation']
|
|
||||||
METADATA_FILE_EXT = '.yml'
|
METADATA_FILE_EXT = '.yml'
|
||||||
LOG_FILE_EXT = '.log'
|
LOG_FILE_EXT = '.log'
|
||||||
RELATED_CATEGORIES = ['app', 'domain', 'group', 'service', 'user']
|
RELATED_CATEGORIES = ['app', 'domain', 'group', 'service', 'user']
|
||||||
|
@ -52,77 +49,67 @@ RELATED_CATEGORIES = ['app', 'domain', 'group', 'service', 'user']
|
||||||
logger = getActionLogger('yunohost.log')
|
logger = getActionLogger('yunohost.log')
|
||||||
|
|
||||||
|
|
||||||
def log_list(category=[], limit=None, with_details=False):
|
def log_list(limit=None, with_details=False, with_suboperations=False):
|
||||||
"""
|
"""
|
||||||
List available logs
|
List available logs
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
limit -- Maximum number of logs
|
limit -- Maximum number of logs
|
||||||
with_details -- Include details (e.g. if the operation was a success). Likely to increase the command time as it needs to open and parse the metadata file for each log... So try to use this in combination with --limit.
|
with_details -- Include details (e.g. if the operation was a success).
|
||||||
|
Likely to increase the command time as it needs to open and parse the
|
||||||
|
metadata file for each log... So try to use this in combination with
|
||||||
|
--limit.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
categories = category
|
|
||||||
is_api = msettings.get('interface') == 'api'
|
is_api = msettings.get('interface') == 'api'
|
||||||
|
|
||||||
# In cli we just display `operation` logs by default
|
operations = []
|
||||||
if not categories:
|
|
||||||
categories = CATEGORIES
|
|
||||||
|
|
||||||
result = collections.OrderedDict()
|
logs = filter(lambda x: x.endswith(METADATA_FILE_EXT),
|
||||||
for category in categories:
|
os.listdir(OPERATIONS_PATH))
|
||||||
result[category] = []
|
logs = list(reversed(sorted(logs)))
|
||||||
|
|
||||||
category_path = os.path.join(CATEGORIES_PATH, category)
|
if limit is not None:
|
||||||
if not os.path.exists(category_path):
|
logs = logs[:limit]
|
||||||
logger.debug(m18n.n('log_category_404', category=category))
|
|
||||||
continue
|
|
||||||
|
|
||||||
logs = filter(lambda x: x.endswith(METADATA_FILE_EXT),
|
for log in logs:
|
||||||
os.listdir(category_path))
|
|
||||||
logs = list(reversed(sorted(logs)))
|
|
||||||
|
|
||||||
if limit is not None:
|
base_filename = log[:-len(METADATA_FILE_EXT)]
|
||||||
logs = logs[:limit]
|
md_filename = log
|
||||||
|
md_path = os.path.join(OPERATIONS_PATH, md_filename)
|
||||||
|
|
||||||
for log in logs:
|
log = base_filename.split("-")
|
||||||
|
|
||||||
base_filename = log[:-len(METADATA_FILE_EXT)]
|
entry = {
|
||||||
md_filename = log
|
"name": base_filename,
|
||||||
md_path = os.path.join(category_path, md_filename)
|
"path": md_path,
|
||||||
|
}
|
||||||
|
entry["description"] = _get_description_from_name(base_filename)
|
||||||
|
try:
|
||||||
|
log_datetime = datetime.strptime(" ".join(log[:2]),
|
||||||
|
"%Y%m%d %H%M%S")
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
entry["started_at"] = log_datetime
|
||||||
|
|
||||||
log = base_filename.split("-")
|
if with_details:
|
||||||
|
|
||||||
entry = {
|
|
||||||
"name": base_filename,
|
|
||||||
"path": md_path,
|
|
||||||
}
|
|
||||||
entry["description"] = _get_description_from_name(base_filename)
|
|
||||||
try:
|
try:
|
||||||
log_datetime = datetime.strptime(" ".join(log[:2]),
|
metadata = read_yaml(md_path)
|
||||||
"%Y%m%d %H%M%S")
|
except Exception as e:
|
||||||
except ValueError:
|
# If we can't read the yaml for some reason, report an error and ignore this entry...
|
||||||
pass
|
logger.error(m18n.n('log_corrupted_md_file', md_file=md_path, error=e))
|
||||||
else:
|
continue
|
||||||
entry["started_at"] = log_datetime
|
entry["success"] = metadata.get("success", "?") if metadata else "?"
|
||||||
|
|
||||||
if with_details:
|
operations.append(entry)
|
||||||
try:
|
|
||||||
metadata = read_yaml(md_path)
|
|
||||||
except Exception as e:
|
|
||||||
# If we can't read the yaml for some reason, report an error and ignore this entry...
|
|
||||||
logger.error(m18n.n('log_corrupted_md_file', md_file=md_path, error=e))
|
|
||||||
continue
|
|
||||||
entry["success"] = metadata.get("success", "?") if metadata else "?"
|
|
||||||
|
|
||||||
result[category].append(entry)
|
|
||||||
|
|
||||||
# Reverse the order of log when in cli, more comfortable to read (avoid
|
# Reverse the order of log when in cli, more comfortable to read (avoid
|
||||||
# unecessary scrolling)
|
# unecessary scrolling)
|
||||||
if not is_api:
|
if not is_api:
|
||||||
for category in result:
|
operations = list(reversed(operations))
|
||||||
result[category] = list(reversed(result[category]))
|
|
||||||
|
|
||||||
return result
|
return {"operation": operations}
|
||||||
|
|
||||||
|
|
||||||
def log_display(path, number=None, share=False, filter_irrelevant=False):
|
def log_display(path, number=None, share=False, filter_irrelevant=False):
|
||||||
|
@ -165,10 +152,7 @@ def log_display(path, number=None, share=False, filter_irrelevant=False):
|
||||||
abs_path = path
|
abs_path = path
|
||||||
log_path = None
|
log_path = None
|
||||||
if not path.startswith('/'):
|
if not path.startswith('/'):
|
||||||
for category in CATEGORIES:
|
abs_path = os.path.join(OPERATIONS_PATH, path)
|
||||||
abs_path = os.path.join(CATEGORIES_PATH, category, path)
|
|
||||||
if os.path.exists(abs_path) or os.path.exists(abs_path + METADATA_FILE_EXT):
|
|
||||||
break
|
|
||||||
|
|
||||||
if os.path.exists(abs_path) and not path.endswith(METADATA_FILE_EXT):
|
if os.path.exists(abs_path) and not path.endswith(METADATA_FILE_EXT):
|
||||||
log_path = abs_path
|
log_path = abs_path
|
||||||
|
|
Loading…
Add table
Reference in a new issue