From 84dc0b2d377ca4fff6a0b1e81dfaf5a6222b57af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 21 Jul 2017 17:39:57 +0300 Subject: [PATCH] MXS-1300: Add enabled log priorities to /maxscale/logs resurce The logging priorities should be displayed as a part of the resource as they can be enabled or disabled at runtime. --- maxctrl/lib/show.js | 1 + server/core/log_manager.cc | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/maxctrl/lib/show.js b/maxctrl/lib/show.js index 22ab28784..e2fe564c0 100644 --- a/maxctrl/lib/show.js +++ b/maxctrl/lib/show.js @@ -112,6 +112,7 @@ exports.builder = function(yargs) { maxctrl(argv, function(host) { return getResource(host, 'maxscale/logs', [ {'Current Log File': 'attributes.log_file'}, + {'Enabled Log Levels': 'attributes.log_priorities'}, {'Parameters': 'attributes.parameters'} ]) }) diff --git a/server/core/log_manager.cc b/server/core/log_manager.cc index a5f248bd6..f2764d143 100644 --- a/server/core/log_manager.cc +++ b/server/core/log_manager.cc @@ -3017,6 +3017,38 @@ const char* mxs_strerror(int error) return strerror_r(error, errbuf, sizeof(errbuf)); } +json_t* get_log_priorities() +{ + json_t* arr = json_array(); + + if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_ERR)) + { + json_array_append_new(arr, json_string("error")); + } + + if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_WARNING)) + { + json_array_append_new(arr, json_string("warning")); + } + + if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_NOTICE)) + { + json_array_append_new(arr, json_string("notice")); + } + + if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO)) + { + json_array_append_new(arr, json_string("info")); + } + + if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_DEBUG)) + { + json_array_append_new(arr, json_string("debug")); + } + + return arr; +} + json_t* mxs_logs_to_json(const char* host) { json_t* param = json_object(); @@ -3038,6 +3070,7 @@ json_t* mxs_logs_to_json(const char* host) json_t* attr = json_object(); json_object_set_new(attr, CN_PARAMETERS, param); json_object_set_new(attr, "log_file", json_string(lm->lm_filewriter.fwr_file->sf_fname)); + json_object_set_new(attr, "log_priorities", get_log_priorities()); json_t* data = json_object(); json_object_set_new(data, CN_ATTRIBUTES, attr);