From 1dba6c413ab6dcc33769d14891802298c8703065 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 22 Feb 2020 10:13:16 -0600 Subject: [PATCH] mgr: allow logging to any channel Signed-off-by: Sage Weil --- src/mgr/ActivePyModules.cc | 24 +++++++++++++++++++----- src/mgr/BaseMgrModule.cc | 8 -------- src/mon/MonClient.h | 3 +++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index e30da4cb0dd..b2f48acf3b2 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -1074,11 +1074,25 @@ void ActivePyModules::cluster_log(const std::string &channel, clog_type prio, { std::lock_guard l(lock); - if (channel == "audit") { - audit_clog->do_log(prio, message); - } else { - clog->do_log(prio, message); - } + auto cl = monc.get_log_client()->create_channel(channel); + map log_to_monitors; + map log_to_syslog; + map log_channel; + map log_prio; + map log_to_graylog; + map log_to_graylog_host; + map log_to_graylog_port; + uuid_d fsid; + string host; + if (parse_log_client_options(g_ceph_context, log_to_monitors, log_to_syslog, + log_channel, log_prio, log_to_graylog, + log_to_graylog_host, log_to_graylog_port, + fsid, host) == 0) + cl->update_config(log_to_monitors, log_to_syslog, + log_channel, log_prio, log_to_graylog, + log_to_graylog_host, log_to_graylog_port, + fsid, host); + cl->do_log(prio, message); } void ActivePyModules::register_client(std::string_view name, std::string addrs) diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index e59c8e46d6c..3ac66e9a9e7 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -558,19 +558,11 @@ ceph_cluster_log(BaseMgrModule *self, PyObject *args) int prio = 0; char *channel = nullptr; char *message = nullptr; - std::vector channels = { "audit", "cluster" }; if (!PyArg_ParseTuple(args, "sis:ceph_cluster_log", &channel, &prio, &message)) { return nullptr; } - if (std::find(channels.begin(), channels.end(), std::string(channel)) == channels.end()) { - std::string msg("Unknown channel: "); - msg.append(channel); - PyErr_SetString(PyExc_ValueError, msg.c_str()); - return nullptr; - } - PyThreadState *tstate = PyEval_SaveThread(); self->py_modules->cluster_log(channel, (clog_type)prio, message); PyEval_RestoreThread(tstate); diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index 52c55fb18f3..7a080f564d4 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -426,6 +426,9 @@ public: void set_log_client(LogClient *clog) { log_client = clog; } + LogClient *get_log_client() { + return log_client; + } int build_initial_monmap(); int get_monmap(); -- 2.39.5