1
1
mirror of https://github.com/tstack/lnav.git synced 2024-09-11 13:05:51 +03:00

[partition] use an underline to mark a partition boundary

This commit is contained in:
Timothy Stack 2014-03-07 06:29:20 -08:00
parent d993d0e8c6
commit 08374381b2
8 changed files with 127 additions and 26 deletions

3
NEWS
View File

@ -36,6 +36,9 @@ lnav v0.6.3:
* Environment variables can now be accessed in SQL queries using
the syntax: $VAR_NAME
* An internal log is kept and written out on a crash.
* Partition bookmarks are now tracked separately from regular user
bookmarks. You can start a partition with the 'partition-name'
command and remove it with the 'clear-partition' command.
lnav v0.6.2:
Features:

View File

@ -204,7 +204,9 @@ through the file.
C Clear all marked lines.
u/U Move forward/backward through any user bookmarks
you have added using the 'm' key.
you have added using the 'm' key. This hotkey will
also jump to the start of any log partitions that have
been created with the 'partition-name' command.
T Toggle the display of the "time offset" column that shows
the time elapsed since the beginning of the logs or the
@ -422,6 +424,17 @@ COMMANDS
Switch the display to the given view, which can be one of:
help, log, text, histogram, db, and schema.
partition-name <name>
Mark the top line in the log view as the start of a new
partition with the given name. The current partition name
will be reflected in the top status bar next to the current
time as well as being available in the 'log_part' column
of the SQL log tables. Partitions can be used to make it
easier to query subsections of log messages.
clear-partition
Clear the partition the top line is a part of.
SQL QUERIES (experimental)
-----------
@ -462,6 +475,9 @@ automatically be displayed after pressing the semicolon (;) key.
All log tables contain at least the following columns:
log_line The line number in the file, starting at zero.
log_part The name of the partition. Use the 'partition-name'
command to mark the start of a new partition in
the log view.
log_time The time of the log entry.
log_idle_msecs The amount of time, in milliseconds, between the
current log message and the previous one.

View File

@ -2642,9 +2642,6 @@ static void usage(void)
" -d file Write debug messages to the given file.\n"
" -V Print version information.\n"
"\n"
" -c cmd Execute a command after the files have been loaded.\n"
" -f path Execute the commands in the given file.\n"
" -n Run without the curses UI.\n"
" -s Load the most recent syslog messages file.\n"
" -a Load all of the most recent log file types.\n"
" -r Load older rotated log files as well.\n"
@ -2652,6 +2649,13 @@ static void usage(void)
" on the standard input.\n"
" -w file Write the contents of the standard input to this file.\n"
"\n"
" -c cmd Execute a command after the files have been loaded.\n"
" -f path Execute the commands in the given file.\n"
" -n Run without the curses UI. (headless mode)\n"
" -S Load session data.\n"
" -q Do not print the log messages after executing all\n"
" of the commands.\n"
"\n"
"Optional arguments:\n"
" logfile1 The log files or directories to view. If a\n"
" directory is given, all of the files in the\n"

View File

@ -920,6 +920,42 @@ static string com_partition_name(string cmdline, vector<string> &args)
return retval;
}
static string com_clear_partition(string cmdline, vector<string> &args)
{
string retval = "";
if (args.size() == 0) {
return "";
}
else if (args.size() == 1) {
textview_curses &tc = lnav_data.ld_views[LNV_LOG];
logfile_sub_source &lss = lnav_data.ld_log_source;
bookmark_vector<vis_line_t> &bv = tc.get_bookmarks()[
&textview_curses::BM_PARTITION];
std::map<content_line_t, bookmark_metadata> &bm = lss.get_user_bookmark_metadata();
vis_line_t part_start;
if (binary_search(bv.begin(), bv.end(), tc.get_top())) {
part_start = tc.get_top();
}
else {
part_start = bv.prev(tc.get_top());
}
if (part_start == -1) {
retval = "error: top line is not in a partition";
}
else {
tc.set_user_mark(
&textview_curses::BM_PARTITION, part_start, false);
bm.erase(lss.at(part_start));
retval = "info: cleared partition name";
}
}
return retval;
}
static string com_summarize(string cmdline, vector<string> &args)
{
static pcrecpp::RE db_column_converter("\"");
@ -1217,6 +1253,7 @@ void init_lnav_commands(readline_context::command_map_t &cmd_map)
cmd_map["open"] = com_open;
cmd_map["close"] = com_close;
cmd_map["partition-name"] = com_partition_name;
cmd_map["clear-partition"] = com_clear_partition;
cmd_map["session"] = com_session;
cmd_map["summarize"] = com_summarize;
cmd_map["switch-to-view"] = com_switch_to_view;

View File

@ -224,8 +224,7 @@ void textview_curses::listview_value_for_row(const listview_curses &lv,
}
#endif
if (binary_search(user_marks.begin(), user_marks.end(), row) ||
binary_search(part_marks.begin(), part_marks.end(), row)) {
if (binary_search(user_marks.begin(), user_marks.end(), row)) {
struct line_range lr(0);
string_attrs_t::iterator iter;
@ -237,6 +236,10 @@ void textview_curses::listview_value_for_row(const listview_curses &lv,
sa.push_back(string_attr(lr, &view_curses::VC_STYLE, A_REVERSE));
}
else if (binary_search(part_marks.begin(), part_marks.end(), row + 1)) {
sa.push_back(string_attr(
line_range(0), &view_curses::VC_STYLE, A_UNDERLINE));
}
}
bool textview_curses::handle_mouse(mouse_event &me)

View File

@ -195,7 +195,6 @@ TESTS = \
test_auto_mem \
test_bookmarks \
test_cmds.sh \
test_line_buffer.sh \
test_line_buffer2 \
test_listview.sh \
test_grep_proc.sh \
@ -225,3 +224,6 @@ DISTCLEANFILES = \
*.diff \
*.index \
*.tmp
distclean-local:
rm -rf sessions

View File

@ -93,13 +93,13 @@ check_PROGRAMS = drive_data_scanner$(EXEEXT) \
test_yajlpp$(EXEEXT)
TESTS = test_ansi_scrubber$(EXEEXT) test_auto_fd$(EXEEXT) \
test_auto_mem$(EXEEXT) test_bookmarks$(EXEEXT) test_cmds.sh \
test_line_buffer.sh test_line_buffer2$(EXEEXT) \
test_listview.sh test_grep_proc.sh test_grep_proc2$(EXEEXT) \
test_hist_source$(EXEEXT) test_json_format.sh \
test_pcrepp$(EXEEXT) test_sql.sh test_sql_coll_func.sh \
test_sql_fs_func.sh test_sql_str_func.sh test_view_colors.sh \
test_vt52_curses.sh test_top_status$(EXEEXT) \
test_data_parser.sh test_yajlpp$(EXEEXT)
test_line_buffer2$(EXEEXT) test_listview.sh test_grep_proc.sh \
test_grep_proc2$(EXEEXT) test_hist_source$(EXEEXT) \
test_json_format.sh test_pcrepp$(EXEEXT) test_sessions.sh \
test_sql.sh test_sql_coll_func.sh test_sql_fs_func.sh \
test_sql_str_func.sh test_view_colors.sh test_vt52_curses.sh \
test_top_status$(EXEEXT) test_data_parser.sh \
test_yajlpp$(EXEEXT)
subdir = test
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/mkinstalldirs $(dist_noinst_SCRIPTS) \
@ -691,6 +691,7 @@ dist_noinst_SCRIPTS = \
test_line_buffer.sh \
test_listview.sh \
test_logfile.sh \
test_sessions.sh \
test_sql.sh \
test_sql_coll_func.sh \
test_sql_str_func.sh \
@ -1152,13 +1153,6 @@ test_cmds.sh.log: test_cmds.sh
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_line_buffer.sh.log: test_line_buffer.sh
@p='test_line_buffer.sh'; \
b='test_line_buffer.sh'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_line_buffer2.log: test_line_buffer2$(EXEEXT)
@p='test_line_buffer2$(EXEEXT)'; \
b='test_line_buffer2'; \
@ -1208,6 +1202,13 @@ test_pcrepp.log: test_pcrepp$(EXEEXT)
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_sessions.sh.log: test_sessions.sh
@p='test_sessions.sh'; \
b='test_sessions.sh'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_sql.sh.log: test_sql.sh
@p='test_sql.sh'; \
b='test_sql.sh'; \
@ -1364,7 +1365,7 @@ distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
distclean-local distclean-tags
dvi: dvi-am
@ -1429,9 +1430,9 @@ uninstall-am:
.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \
clean-checkPROGRAMS clean-generic cscopelist-am ctags ctags-am \
distclean distclean-compile distclean-generic distclean-tags \
distdir dvi dvi-am html html-am info info-am install \
install-am install-data install-data-am install-dvi \
distclean distclean-compile distclean-generic distclean-local \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \
install-pdf install-pdf-am install-ps install-ps-am \
@ -1445,6 +1446,9 @@ simple-db.db: simple-db.sql
rm -f $@
$(SQLITE3_CMD) $@ < $(srcdir)/simple-db.sql
distclean-local:
rm -rf sessions
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

View File

@ -137,9 +137,41 @@ run_test ${lnav_test} -n \
-c ":write-csv-to -" \
${test_dir}/logfile_access_log.0
check_output "errors are not reported" <<EOF
check_output "partition-name does not work" <<EOF
log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,c_ip,cs_method,cs_referer,cs_uri_query,cs_uri_stem,cs_user_agent,cs_username,cs_version,sc_bytes,sc_status
0,p.0,2009-07-20 22:59:26.000,0,info,0,192.168.202.254,GET,-,<NULL>,/vmw/cgi/tramp,gPXE/0.9.7,-,HTTP/1.0,134,200
1,middle,2009-07-20 22:59:29.000,3000,error,0,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkboot.gz,gPXE/0.9.7,-,HTTP/1.0,46210,404
2,middle,2009-07-20 22:59:29.000,0,info,0,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkernel.gz,gPXE/0.9.7,-,HTTP/1.0,78929,200
EOF
run_test ${lnav_test} -n \
-c ":goto 1" \
-c ":partition-name middle" \
-c ":clear-partition" \
-c ";select * from access_log" \
-c ":write-csv-to -" \
${test_dir}/logfile_access_log.0
check_output "clear-partition does not work" <<EOF
log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,c_ip,cs_method,cs_referer,cs_uri_query,cs_uri_stem,cs_user_agent,cs_username,cs_version,sc_bytes,sc_status
0,p.0,2009-07-20 22:59:26.000,0,info,0,192.168.202.254,GET,-,<NULL>,/vmw/cgi/tramp,gPXE/0.9.7,-,HTTP/1.0,134,200
1,p.0,2009-07-20 22:59:29.000,3000,error,0,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkboot.gz,gPXE/0.9.7,-,HTTP/1.0,46210,404
2,p.0,2009-07-20 22:59:29.000,0,info,0,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkernel.gz,gPXE/0.9.7,-,HTTP/1.0,78929,200
EOF
run_test ${lnav_test} -n \
-c ":goto 1" \
-c ":partition-name middle" \
-c ":goto 2" \
-c ":clear-partition" \
-c ";select * from access_log" \
-c ":write-csv-to -" \
${test_dir}/logfile_access_log.0
check_output "clear-partition does not work when in the middle of a part" <<EOF
log_line,log_part,log_time,log_idle_msecs,log_level,log_mark,c_ip,cs_method,cs_referer,cs_uri_query,cs_uri_stem,cs_user_agent,cs_username,cs_version,sc_bytes,sc_status
0,p.0,2009-07-20 22:59:26.000,0,info,0,192.168.202.254,GET,-,<NULL>,/vmw/cgi/tramp,gPXE/0.9.7,-,HTTP/1.0,134,200
1,p.0,2009-07-20 22:59:29.000,3000,error,0,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkboot.gz,gPXE/0.9.7,-,HTTP/1.0,46210,404
2,p.0,2009-07-20 22:59:29.000,0,info,0,192.168.202.254,GET,-,<NULL>,/vmw/vSphere/default/vmkernel.gz,gPXE/0.9.7,-,HTTP/1.0,78929,200
EOF