[sql] add log_msg_line() function

Related to #1219
pull/1235/head
Tim Stack 5 months ago
parent 6736a8db81
commit 53d5e408fa

@ -116,6 +116,9 @@ Features:
the desired file.
* Binary files are now displayed as a hex dump with ASCII
representation (where applicable).
* Added a `log_msg_line()` function that will return the
line number of the start of the currently focused
message in the log view.
Bug Fixes:
* Binary data piped into stdin should now be treated the same

@ -2621,6 +2621,17 @@ log10(*x*)
----
.. _log_msg_line:
log_msg_line()
^^^^^^^^^^^^^^
Return the starting line number of the focused log message.
----
.. _log_top_datetime:
log_top_datetime()
@ -2637,7 +2648,7 @@ log_top_datetime()
log_top_line()
^^^^^^^^^^^^^^
Return the line number at the top of the log view.
Return the number of the focused line of the log view.
----

@ -51,6 +51,30 @@ sql_log_top_line()
return (int64_t) tc.get_top();
}
static nonstd::optional<int64_t>
sql_log_msg_line()
{
const auto& tc = lnav_data.ld_views[LNV_LOG];
if (tc.get_inner_height() == 0_vl) {
return nonstd::nullopt;
}
auto top_line = tc.get_top();
auto line_pair_opt = lnav_data.ld_log_source.find_line_with_file(top_line);
if (!line_pair_opt) {
return nonstd::nullopt;
}
auto ll = line_pair_opt.value().second;
while (ll->is_continued()) {
--ll;
top_line -= 1_vl;
}
return (int64_t) top_line;
}
static nonstd::optional<std::string>
sql_log_top_datetime()
{
@ -134,10 +158,17 @@ state_extension_functions(struct FuncDef** basic_funcs,
static struct FuncDef state_funcs[] = {
sqlite_func_adapter<decltype(&sql_log_top_line), sql_log_top_line>::
builder(
help_text("log_top_line",
"Return the line number at the top of the log view.")
help_text(
"log_top_line",
"Return the number of the focused line of the log view.")
.sql_function()),
sqlite_func_adapter<decltype(&sql_log_msg_line), sql_log_msg_line>::
builder(help_text("log_msg_line",
"Return the starting line number of the focused "
"log message.")
.sql_function()),
sqlite_func_adapter<decltype(&sql_log_top_datetime),
sql_log_top_datetime>::
builder(help_text("log_top_datetime",

@ -588,6 +588,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_sql.sh_2959f0c70fca61a07c6c772f193e73022f7794f1.out \
$(srcdir)/%reldir%/test_sql.sh_2a16a6fd0ff235a7877e1ea93b22d873a3609402.err \
$(srcdir)/%reldir%/test_sql.sh_2a16a6fd0ff235a7877e1ea93b22d873a3609402.out \
$(srcdir)/%reldir%/test_sql.sh_2c60ed41369d667d1e2a563d54f8edf84682e526.err \
$(srcdir)/%reldir%/test_sql.sh_2c60ed41369d667d1e2a563d54f8edf84682e526.out \
$(srcdir)/%reldir%/test_sql.sh_2cc8a92c6eb73741080b187a2670d309b8171c90.err \
$(srcdir)/%reldir%/test_sql.sh_2cc8a92c6eb73741080b187a2670d309b8171c90.out \
$(srcdir)/%reldir%/test_sql.sh_2f15b8a38673ac4db45dc6ed2eafe609c332575b.err \
@ -624,6 +626,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_sql.sh_6edb0c8d5323d1b962d90dd6ecdd7eee9008d7b5.out \
$(srcdir)/%reldir%/test_sql.sh_753c343a256d1286750314957d1b4e155464e03e.err \
$(srcdir)/%reldir%/test_sql.sh_753c343a256d1286750314957d1b4e155464e03e.out \
$(srcdir)/%reldir%/test_sql.sh_7593b39f4be6fd2124ec7cf10835ee015d475b16.err \
$(srcdir)/%reldir%/test_sql.sh_7593b39f4be6fd2124ec7cf10835ee015d475b16.out \
$(srcdir)/%reldir%/test_sql.sh_764306f0e5f610ba71f521ba3d19fe158ece0ba5.err \
$(srcdir)/%reldir%/test_sql.sh_764306f0e5f610ba71f521ba3d19fe158ece0ba5.out \
$(srcdir)/%reldir%/test_sql.sh_7f664c9cda0ae1c48333e21051b5e0eeafd5b4bc.err \
@ -672,6 +676,8 @@ EXPECTED_FILES = \
$(srcdir)/%reldir%/test_sql.sh_dd540973a0dc86320d84706845a15608196ae5be.out \
$(srcdir)/%reldir%/test_sql.sh_e70dc7d2b686c7f91c2b41b10f3920c50f3ea405.err \
$(srcdir)/%reldir%/test_sql.sh_e70dc7d2b686c7f91c2b41b10f3920c50f3ea405.out \
$(srcdir)/%reldir%/test_sql.sh_fea98f976873ee7b55e6f322dda42719a19fb3f0.err \
$(srcdir)/%reldir%/test_sql.sh_fea98f976873ee7b55e6f322dda42719a19fb3f0.out \
$(srcdir)/%reldir%/test_sql.sh_ff8a978fc0de0fed675a3cd1454cf435a6856fd5.err \
$(srcdir)/%reldir%/test_sql.sh_ff8a978fc0de0fed675a3cd1454cf435a6856fd5.out \
$(srcdir)/%reldir%/test_sql_anno.sh_028d5d5af2f3519b59d349d41cb7ecf385253b51.err \

@ -3434,6 +3434,11 @@ For support questions, email:
log_msg_line()
══════════════════════════════════════════════════════════════════════
Return the starting line number of the focused log message.
log_top_datetime()
══════════════════════════════════════════════════════════════════════
Return the timestamp of the line at the top of the log view.
@ -3441,7 +3446,7 @@ For support questions, email:
log_top_line()
══════════════════════════════════════════════════════════════════════
Return the line number at the top of the log view.
Return the number of the focused line of the log view.
logfmt2json(str)

@ -0,0 +1,2 @@
log_top_line() log_msg_line() 
1 0

@ -0,0 +1,2 @@
log_top_line() log_msg_line() 
 2  2

@ -0,0 +1,2 @@
log_top_line() log_msg_line() 
<NULL> <NULL>

@ -281,14 +281,19 @@ EOF
run_cap_test ${lnav_test} -n \
-c ":goto 2" \
-c ";SELECT log_top_line()" \
-c ";SELECT log_top_line(), log_msg_line()" \
${test_dir}/logfile_uwsgi.0
run_cap_test ${lnav_test} -n \
-c ":goto 2" \
-c ";SELECT log_top_line()" \
-c ";SELECT log_top_line(), log_msg_line()" \
${test_dir}/logfile_empty.0
run_cap_test ${lnav_test} -n \
-c ":goto 1" \
-c ";SELECT log_top_line(), log_msg_line()" \
${test_dir}/logfile_multiline.0
run_cap_test ${lnav_test} -n \
-c ":goto 2" \
-c ";SELECT log_top_datetime()" \

Loading…
Cancel
Save