From 06b917856f9410a285b578ab2bd81416556deb64 Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Wed, 9 Mar 2016 15:12:55 +0100 Subject: [PATCH] virt-admin: Wire-up the logging APIs Finally, now that all APIs have been introduced, wire them up to virt-admin and introduce daemon-log-outputs and daemon-log-filters commands. Signed-off-by: Erik Skultety --- tools/virt-admin.c | 120 +++++++++++++++++++++++++++++++++++++++++++ tools/virt-admin.pod | 54 +++++++++++++++++++ 2 files changed, 174 insertions(+) diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 70b0e517f4..0fa1c000c4 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -971,6 +971,114 @@ cmdSrvClientsSet(vshControl *ctl, const vshCmd *cmd) goto cleanup; } +/* -------------------------- + * Command daemon-log-filters + * -------------------------- + */ +static const vshCmdInfo info_daemon_log_filters[] = { + {.name = "help", + .data = N_("fetch or set the currently defined set of logging filters on " + "daemon") + }, + {.name = "desc", + .data = N_("Depending on whether run with or without options, the command " + "fetches or redefines the existing active set of filters on " + "daemon.") + }, + {.name = NULL} +}; + +static const vshCmdOptDef opts_daemon_log_filters[] = { + {.name = "filters", + .type = VSH_OT_STRING, + .help = N_("redefine the existing set of logging filters"), + .flags = VSH_OFLAG_EMPTY_OK + }, + {.name = NULL} +}; + +static bool +cmdDaemonLogFilters(vshControl *ctl, const vshCmd *cmd) +{ + int nfilters; + char *filters = NULL; + vshAdmControlPtr priv = ctl->privData; + + if (vshCommandOptBool(cmd, "filters")) { + if ((vshCommandOptStringReq(ctl, cmd, "filters", + (const char **) &filters) < 0 || + virAdmConnectSetLoggingFilters(priv->conn, filters, 0) < 0)) { + vshError(ctl, _("Unable to change daemon logging settings")); + return false; + } + } else { + if ((nfilters = virAdmConnectGetLoggingFilters(priv->conn, + &filters, 0)) < 0) { + vshError(ctl, _("Unable to get daemon logging filters information")); + return false; + } + + vshPrintExtra(ctl, " %-15s", _("Logging filters: ")); + vshPrint(ctl, "%s\n", filters ? filters : ""); + } + + return true; +} + +/* -------------------------- + * Command daemon-log-outputs + * -------------------------- + */ +static const vshCmdInfo info_daemon_log_outputs[] = { + {.name = "help", + .data = N_("fetch or set the currently defined set of logging outputs on " + "daemon") + }, + {.name = "desc", + .data = N_("Depending on whether run with or without options, the command " + "fetches or redefines the existing active set of outputs on " + "daemon.") + }, + {.name = NULL} +}; + +static const vshCmdOptDef opts_daemon_log_outputs[] = { + {.name = "outputs", + .type = VSH_OT_STRING, + .help = N_("redefine the existing set of logging outputs"), + .flags = VSH_OFLAG_EMPTY_OK + }, + {.name = NULL} +}; + +static bool +cmdDaemonLogOutputs(vshControl *ctl, const vshCmd *cmd) +{ + int noutputs; + char *outputs = NULL; + vshAdmControlPtr priv = ctl->privData; + + if (vshCommandOptBool(cmd, "outputs")) { + if ((vshCommandOptStringReq(ctl, cmd, "outputs", + (const char **) &outputs) < 0 || + virAdmConnectSetLoggingOutputs(priv->conn, outputs, 0) < 0)) { + vshError(ctl, _("Unable to change daemon logging settings")); + return false; + } + } else { + if ((noutputs = virAdmConnectGetLoggingOutputs(priv->conn, + &outputs, 0)) < 0) { + vshError(ctl, _("Unable to get daemon logging outputs information")); + return false; + } + + vshPrintExtra(ctl, " %-15s", _("Logging outputs: ")); + vshPrint(ctl, "%s\n", outputs ? outputs : ""); + } + + return true; +} + static void * vshAdmConnectionHandler(vshControl *ctl) { @@ -1341,6 +1449,18 @@ static const vshCmdDef managementCmds[] = { .info = info_srv_clients_set, .flags = 0 }, + {.name = "daemon-log-filters", + .handler = cmdDaemonLogFilters, + .opts = opts_daemon_log_filters, + .info = info_daemon_log_filters, + .flags = 0 + }, + {.name = "daemon-log-outputs", + .handler = cmdDaemonLogOutputs, + .opts = opts_daemon_log_outputs, + .info = info_daemon_log_outputs, + .flags = 0 + }, {.name = NULL} }; diff --git a/tools/virt-admin.pod b/tools/virt-admin.pod index 443730ebf5..ef140824cb 100644 --- a/tools/virt-admin.pod +++ b/tools/virt-admin.pod @@ -155,6 +155,60 @@ change its internal configuration. Lists all manageable servers contained within the daemon the client is currently connected to. +=item B [I<--filters> B] + +When run without arguments, this returns the currently defined set of logging +filters. Providing an argument will cause the command to define a new set of +logging filters. + +=over 4 + +=item I<--filters> + +Define a new set of logging filters where multiple filters are delimited by +space. Each filter must conform to the form described in detail by +I (section 'Logging filters'). + +=back + +B + + To define a filter which suppresses all e.g. 'virObjectUnref' DEBUG + messages, use the following: + + $ virt-admin daemon-log-filters "4:util.object" + + (Note the '.' symbol which can be used to more fine-grained filters tailored + to specific modules, in contrast, to affect the whole directory containing + several modules this would become "4:util"): + +=item B [I<--outputs> B] + +When run without arguments, this returns the currently defined set of logging +outputs. Providing an argument will cause the command to define a new set of +logging outputs. + +=over 4 + +=item I<--outputs> + +Define a new set of logging outputs where multiple outputs are delimited by +space. Each output must conform to the form described in detail by +I (section 'Logging outputs'). + +=back + +B + + To replace the current setting for logging outputs with one that writes to + a file while logging errors only, the following could be used: + + $ virt-admin daemon-log-outputs "4:file:" + + To define multiple outputs at once they need to be delimited by spaces: + + $ virt-admin daemon-log-outputs "4:stderr 2:syslog:" + =back =head1 SERVER COMMANDS -- 2.39.5