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,33 +49,24 @@ 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()
|
|
||||||
for category in categories:
|
|
||||||
result[category] = []
|
|
||||||
|
|
||||||
category_path = os.path.join(CATEGORIES_PATH, category)
|
|
||||||
if not os.path.exists(category_path):
|
|
||||||
logger.debug(m18n.n('log_category_404', category=category))
|
|
||||||
continue
|
|
||||||
|
|
||||||
logs = filter(lambda x: x.endswith(METADATA_FILE_EXT),
|
logs = filter(lambda x: x.endswith(METADATA_FILE_EXT),
|
||||||
os.listdir(category_path))
|
os.listdir(OPERATIONS_PATH))
|
||||||
logs = list(reversed(sorted(logs)))
|
logs = list(reversed(sorted(logs)))
|
||||||
|
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
|
@ -88,7 +76,7 @@ def log_list(category=[], limit=None, with_details=False):
|
||||||
|
|
||||||
base_filename = log[:-len(METADATA_FILE_EXT)]
|
base_filename = log[:-len(METADATA_FILE_EXT)]
|
||||||
md_filename = log
|
md_filename = log
|
||||||
md_path = os.path.join(category_path, md_filename)
|
md_path = os.path.join(OPERATIONS_PATH, md_filename)
|
||||||
|
|
||||||
log = base_filename.split("-")
|
log = base_filename.split("-")
|
||||||
|
|
||||||
|
@ -114,15 +102,14 @@ def log_list(category=[], limit=None, with_details=False):
|
||||||
continue
|
continue
|
||||||
entry["success"] = metadata.get("success", "?") if metadata else "?"
|
entry["success"] = metadata.get("success", "?") if metadata else "?"
|
||||||
|
|
||||||
result[category].append(entry)
|
operations.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