mirror of
https://github.com/tstack/lnav.git
synced 2024-09-11 13:05:51 +03:00
parent
cbd8308b36
commit
d17f7b1940
@ -1779,6 +1779,8 @@ static void handle_paging_key(int ch)
|
||||
buffer);
|
||||
}
|
||||
}
|
||||
lnav_data.ld_rl_view->add_possibility(
|
||||
LNM_COMMAND, "levelname", logline::level_names);
|
||||
lnav_data.ld_mode = LNM_COMMAND;
|
||||
lnav_data.ld_rl_view->focus(LNM_COMMAND, ":");
|
||||
lnav_data.ld_bottom_source.set_prompt("Enter an lnav command: "
|
||||
@ -4159,6 +4161,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
init_lnav_commands(lnav_commands);
|
||||
|
||||
lnav_data.ld_log_source.add_filter(&lnav_data.ld_level_filter);
|
||||
|
||||
lnav_data.ld_views[LNV_HELP].
|
||||
set_sub_source(new plain_text_source(help_txt));
|
||||
lnav_data.ld_views[LNV_HELP].set_word_wrap(true);
|
||||
|
22
src/lnav.hh
22
src/lnav.hh
@ -132,6 +132,27 @@ void sqlite_close_wrapper(void *mem);
|
||||
typedef std::pair<int, int> ppid_time_pair_t;
|
||||
typedef std::pair<ppid_time_pair_t, std::string> session_pair_t;
|
||||
|
||||
class level_filter : public logfile_filter {
|
||||
public:
|
||||
level_filter()
|
||||
: logfile_filter(EXCLUDE, ""),
|
||||
lf_min_level(logline::LEVEL_UNKNOWN) {
|
||||
};
|
||||
|
||||
bool matches(const logline &ll, const std::string &line)
|
||||
{
|
||||
return (ll.get_level() & ~logline::LEVEL__FLAGS) < this->lf_min_level;
|
||||
};
|
||||
|
||||
std::string to_command(void)
|
||||
{
|
||||
return ("set-min-log-level " +
|
||||
std::string(logline::level_names[this->lf_min_level]));
|
||||
};
|
||||
|
||||
logline::level_t lf_min_level;
|
||||
};
|
||||
|
||||
struct _lnav_data {
|
||||
std::string ld_session_id;
|
||||
time_t ld_session_time;
|
||||
@ -174,6 +195,7 @@ struct _lnav_data {
|
||||
vis_line_t ld_search_start_line;
|
||||
readline_curses * ld_rl_view;
|
||||
|
||||
level_filter ld_level_filter;
|
||||
logfile_sub_source ld_log_source;
|
||||
hist_source ld_hist_source;
|
||||
int ld_hist_zoom;
|
||||
|
@ -551,7 +551,7 @@ public:
|
||||
pf_pcre(code) { };
|
||||
virtual ~pcre_filter() { };
|
||||
|
||||
bool matches(const string &line)
|
||||
bool matches(const logline &ll, const string &line)
|
||||
{
|
||||
pcre_context_static<30> pc;
|
||||
pcre_input pi(line);
|
||||
@ -1360,6 +1360,32 @@ static string com_save_session(string cmdline, vector<string> &args)
|
||||
return "";
|
||||
}
|
||||
|
||||
static string com_set_min_log_level(string cmdline, vector<string> &args)
|
||||
{
|
||||
string retval = "error: expecting log level name";
|
||||
|
||||
if (args.empty()) {
|
||||
args.push_back("levelname");
|
||||
}
|
||||
else if (args.size() == 2) {
|
||||
logline::level_t new_level;
|
||||
|
||||
new_level = logline::string2level(
|
||||
args[1].c_str(), args[1].size(), true);
|
||||
if (lnav_data.ld_level_filter.lf_min_level != new_level) {
|
||||
lnav_data.ld_level_filter.lf_min_level = new_level;
|
||||
lnav_data.ld_log_source.filter_changed();
|
||||
|
||||
rebuild_indexes(true);
|
||||
}
|
||||
|
||||
retval = ("info: minimum log level is now -- " +
|
||||
string(logline::level_names[new_level]));
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void init_lnav_commands(readline_context::command_map_t &cmd_map)
|
||||
{
|
||||
cmd_map["adjust-log-time"] = com_adjust_log_time;
|
||||
@ -1390,6 +1416,7 @@ void init_lnav_commands(readline_context::command_map_t &cmd_map)
|
||||
cmd_map["switch-to-view"] = com_switch_to_view;
|
||||
cmd_map["load-session"] = com_load_session;
|
||||
cmd_map["save-session"] = com_save_session;
|
||||
cmd_map["set-min-log-level"] = com_set_min_log_level;
|
||||
|
||||
if (getenv("LNAV_SRC") != NULL) {
|
||||
cmd_map["add-test"] = com_add_test;
|
||||
|
@ -62,7 +62,7 @@ string_attr_type logline::L_TIMESTAMP;
|
||||
string_attr_type logline::L_FILE;
|
||||
string_attr_type logline::L_PARTITION;
|
||||
|
||||
const char *logline::level_names[LEVEL__MAX] = {
|
||||
const char *logline::level_names[LEVEL__MAX + 1] = {
|
||||
"unknown",
|
||||
"trace",
|
||||
"debug",
|
||||
@ -71,6 +71,8 @@ const char *logline::level_names[LEVEL__MAX] = {
|
||||
"error",
|
||||
"critical",
|
||||
"fatal",
|
||||
|
||||
NULL
|
||||
};
|
||||
|
||||
static int strncasestr_i(const char *s1, const char *s2, size_t len)
|
||||
|
@ -53,6 +53,8 @@
|
||||
#include "view_curses.hh"
|
||||
#include "shared_buffer.hh"
|
||||
|
||||
class logline;
|
||||
|
||||
class logfile_filter {
|
||||
public:
|
||||
typedef enum {
|
||||
@ -78,7 +80,7 @@ public:
|
||||
void enable(void) { this->lf_enabled = true; };
|
||||
void disable(void) { this->lf_enabled = false; };
|
||||
|
||||
virtual bool matches(const std::string &line) = 0;
|
||||
virtual bool matches(const logline &ll, const std::string &line) = 0;
|
||||
|
||||
virtual std::string to_command(void) = 0;
|
||||
|
||||
@ -126,7 +128,7 @@ public:
|
||||
LEVEL__FLAGS = (LEVEL_MARK | LEVEL_CONTINUED)
|
||||
} level_t;
|
||||
|
||||
static const char *level_names[LEVEL__MAX];
|
||||
static const char *level_names[LEVEL__MAX + 1];
|
||||
|
||||
static level_t string2level(const char *levelstr, size_t len = -1, bool exact = false);
|
||||
|
||||
|
@ -311,7 +311,7 @@ logfile_filter::type_t logfile::check_filter(iterator ll,
|
||||
|
||||
if (line_value.empty())
|
||||
this->read_line(ll, line_value);
|
||||
matched = filter->matches(line_value);
|
||||
matched = filter->matches(*ll, line_value);
|
||||
|
||||
switch (filter->get_type()) {
|
||||
case logfile_filter::INCLUDE:
|
||||
|
@ -86,6 +86,10 @@ public:
|
||||
this->lss_filter_generation += 1;
|
||||
};
|
||||
|
||||
void filter_changed(void) {
|
||||
this->lss_filter_generation += 1;
|
||||
};
|
||||
|
||||
void set_filter_enabled(logfile_filter *filter, bool enabled) {
|
||||
if (enabled) {
|
||||
filter->enable();
|
||||
|
@ -199,3 +199,12 @@ check_output "write-json-to is not working" <<EOF
|
||||
}
|
||||
]
|
||||
EOF
|
||||
|
||||
|
||||
run_test ${lnav_test} -n \
|
||||
-c ":set-min-log-level error" \
|
||||
${test_dir}/logfile_access_log.0
|
||||
|
||||
check_output "set-min-log-level is not working" <<EOF
|
||||
192.168.202.254 - - [20/Jul/2009:22:59:29 +0000] "GET /vmw/vSphere/default/vmkboot.gz HTTP/1.0" 404 46210 "-" "gPXE/0.9.7"
|
||||
EOF
|
||||
|
Loading…
Reference in New Issue
Block a user