From 30b4ed431e847c6cd9183a122f758ad0ab327820 Mon Sep 17 00:00:00 2001 From: John Spray Date: Sun, 25 Jun 2017 18:22:07 -0400 Subject: [PATCH] mon: limit `log last` to INFO by default + allow setting The syntax is crude because we only have positional arguments, but anyone who wants anything different can probably handle saying how many lines they want. INFO is the same default setting as "ceph -w". Signed-off-by: John Spray --- src/mon/LogMonitor.cc | 31 ++++++++++++++++++++++++++++++- src/mon/MonCommands.h | 4 +++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index cc5fd6bcb4fd2..76a725600139b 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -403,13 +403,42 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) if (f) { f->open_array_section("tail"); } + + std::string level_str; + clog_type level; + if (cmd_getval(g_ceph_context, cmdmap, "level", level_str)) { + if (level_str == "debug") { + level = CLOG_DEBUG; + } else if (level_str == "info") { + level = CLOG_INFO; + } else if (level_str == "sec") { + level = CLOG_SEC; + } else if (level_str == "warn") { + level = CLOG_WARN; + } else if (level_str == "error") { + level = CLOG_ERROR; + } else { + ss << "Invalid severity '" << level_str << "'"; + mon->reply_command(op, -EINVAL, ss.str(), get_last_committed()); + return true; + } + } else { + level = CLOG_INFO; + } + auto p = summary.tail.end(); while (num > 0 && p != summary.tail.begin()) { - num--; + if (p->prio >= level) { + num--; + } --p; } ostringstream ss; for ( ; p != summary.tail.end(); ++p) { + if (p->prio < level) { + continue; + } + if (f) { f->dump_object("entry", *p); } else { diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index bf868d7687e0b..8ab55e576e46f 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -197,7 +197,9 @@ COMMAND_WITH_FLAG("scrub", "scrub the monitor stores", \ COMMAND("fsid", "show cluster FSID/UUID", "mon", "r", "cli,rest") 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", \ +COMMAND("log last " + "name=num,type=CephInt,range=1,req=false " + "name=level,type=CephChoices,strings=debug|info|sec|warn|error,req=false", \ "print last few lines of the cluster log", \ "mon", "rw", "cli,rest") COMMAND_WITH_FLAG("injectargs " \ -- 2.39.5