From d23452d013173fa9d68da9581bae14b41dcb624e Mon Sep 17 00:00:00 2001 From: John Spray Date: Sun, 25 Jun 2017 18:50:39 -0400 Subject: [PATCH] mon: filter `log last` by channel, default to `cluster` Caller can pass "*" to get old behaviour (audit and cluster mixed together). The audit log messages are visually messy and usually not of interest to someone trying to see what their cluster is doing. Signed-off-by: John Spray --- src/mon/LogMonitor.cc | 15 +++++++++++++-- src/mon/MonCommands.h | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 76a72560013..50ae98cea3b 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -426,16 +426,27 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) level = CLOG_INFO; } + std::string channel; + if (!cmd_getval(g_ceph_context, cmdmap, "channel", channel)) { + channel = CLOG_CHANNEL_DEFAULT; + } + + // We'll apply this twice, once while counting out lines + // and once while outputting them. + auto match = [level, channel](const LogEntry &entry) { + return entry.prio >= level && (entry.channel == channel || channel == "*"); + }; + auto p = summary.tail.end(); while (num > 0 && p != summary.tail.begin()) { - if (p->prio >= level) { + if (match(*p)) { num--; } --p; } ostringstream ss; for ( ; p != summary.tail.end(); ++p) { - if (p->prio < level) { + if (!match(*p)) { continue; } diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 8ab55e576e4..9328efb4528 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -199,7 +199,8 @@ COMMAND("log name=logtext,type=CephString,n=N", \ "log supplied text to the monitor log", "mon", "rw", "cli,rest") COMMAND("log last " "name=num,type=CephInt,range=1,req=false " - "name=level,type=CephChoices,strings=debug|info|sec|warn|error,req=false", \ + "name=level,type=CephChoices,strings=debug|info|sec|warn|error,req=false " + "name=channel,type=CephChoices,strings=*|cluster|audit,req=false", \ "print last few lines of the cluster log", \ "mon", "rw", "cli,rest") COMMAND_WITH_FLAG("injectargs " \ -- 2.47.3