From 5676f05dfbfd3e702ea715df0a8dae31183c792b Mon Sep 17 00:00:00 2001 From: ljf Date: Mon, 4 Jun 2018 04:04:10 +0200 Subject: [PATCH] [enh] Better help for log list action --- data/actionsmap/yunohost.yml | 4 ++-- locales/en.json | 1 + src/yunohost/log.py | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/data/actionsmap/yunohost.yml b/data/actionsmap/yunohost.yml index 78b6433f8..ec150c1ec 100644 --- a/data/actionsmap/yunohost.yml +++ b/data/actionsmap/yunohost.yml @@ -1614,8 +1614,8 @@ log: action_help: List logs api: GET /logs arguments: - categories: - help: Log categories to display (default operations) + category: + help: Log category to display (default operations), could be operation, history, package, system, access, service or app nargs: "*" -l: full: --limit diff --git a/locales/en.json b/locales/en.json index 1b97fd90f..9d4267de6 100644 --- a/locales/en.json +++ b/locales/en.json @@ -206,6 +206,7 @@ "ip6tables_unavailable": "You cannot play with ip6tables here. You are either in a container or your kernel does not support it", "iptables_unavailable": "You cannot play with iptables here. You are either in a container or your kernel does not support it", "log_corrupted_md_file": "The yaml metadata file associated with logs is corrupted : '{md_file}'", + "log_category_404": "The log category '{category}' does not exist", "log_does_exists": "There is not operation log with the name '{log}', use 'yunohost log list to see all available operation logs'", "log_operation_unit_unclosed_properly": "Operation unit has not been closed properly", "log_app_removelist": "Remove an application list", diff --git a/src/yunohost/log.py b/src/yunohost/log.py index 156e8aa0f..7adee7e73 100644 --- a/src/yunohost/log.py +++ b/src/yunohost/log.py @@ -46,7 +46,7 @@ RELATED_CATEGORIES = ['app', 'domain', 'service', 'user'] logger = getActionLogger('yunohost.log') -def log_list(categories=[], limit=None): +def log_list(category=[], limit=None): """ List available logs @@ -54,6 +54,9 @@ def log_list(categories=[], limit=None): limit -- Maximum number of logs """ + categories = category + + # In cli we just display `operation` logs by default if not categories: is_api = msettings.get('interface') == 'api' categories = ["operation"] if not is_api else CATEGORIES @@ -64,6 +67,8 @@ def log_list(categories=[], limit=None): category_path = os.path.join(CATEGORIES_PATH, category) if not os.path.exists(category_path): + logger.warning(m18n.n('log_category_404', category=category)) + continue logs = filter(lambda x: x.endswith(METADATA_FILE_EXT), os.listdir(category_path))