mirror of
https://github.com/tstack/lnav.git
synced 2024-09-11 13:05:51 +03:00
[sql] fix .msgformats command
This commit is contained in:
parent
82c978e0cf
commit
90d6dcaf2b
@ -57,13 +57,6 @@ using namespace lnav::roles::literals;
|
||||
|
||||
exec_context INIT_EXEC_CONTEXT;
|
||||
|
||||
static const std::string MSG_FORMAT_STMT = R"(
|
||||
SELECT count(*) AS total, min(log_line) AS log_line, log_msg_format
|
||||
FROM all_logs
|
||||
GROUP BY log_msg_format
|
||||
ORDER BY total DESC
|
||||
)";
|
||||
|
||||
int
|
||||
sql_progress(const struct log_cursor& lc)
|
||||
{
|
||||
@ -288,10 +281,6 @@ execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
|
||||
}
|
||||
}
|
||||
|
||||
if (stmt_str == ".msgformats") {
|
||||
stmt_str = MSG_FORMAT_STMT;
|
||||
}
|
||||
|
||||
ec.ec_accumulator->clear();
|
||||
|
||||
const auto& source = ec.ec_source.back();
|
||||
|
@ -177,6 +177,34 @@ sql_cmd_schema(exec_context& ec,
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
static Result<std::string, lnav::console::user_message>
|
||||
sql_cmd_msgformats(exec_context& ec,
|
||||
std::string cmdline,
|
||||
std::vector<std::string>& args)
|
||||
{
|
||||
static const std::string MSG_FORMAT_STMT = R"(
|
||||
SELECT count(*) AS total,
|
||||
min(log_time),
|
||||
humanize_duration(timediff(max(log_time), min(log_time))) AS duration,
|
||||
group_concat(DISTINCT log_format) AS log_formats,
|
||||
log_msg_format
|
||||
FROM all_logs
|
||||
GROUP BY log_msg_format
|
||||
HAVING total > 1
|
||||
ORDER BY total DESC
|
||||
)";
|
||||
|
||||
std::string retval;
|
||||
|
||||
if (args.empty()) {
|
||||
return Ok(retval);
|
||||
}
|
||||
|
||||
std::string alt;
|
||||
|
||||
return execute_sql(ec, MSG_FORMAT_STMT, alt);
|
||||
}
|
||||
|
||||
static Result<std::string, lnav::console::user_message>
|
||||
sql_cmd_generic(exec_context& ec,
|
||||
std::string cmdline,
|
||||
@ -205,8 +233,11 @@ static readline_context::command_t sql_commands[] = {
|
||||
},
|
||||
{
|
||||
".msgformats",
|
||||
sql_cmd_schema,
|
||||
help_text(".msgformats", "df").sql_command(),
|
||||
sql_cmd_msgformats,
|
||||
help_text(".msgformats",
|
||||
"Executes a query that will summarize the different message "
|
||||
"formats found in the logs")
|
||||
.sql_command(),
|
||||
},
|
||||
{
|
||||
".read",
|
||||
|
@ -608,8 +608,6 @@ EXPECTED_FILES = \
|
||||
$(srcdir)/%reldir%/test_sql.sh_528e48a03cdfa7cfbe263a6e22a65606247a8a95.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_5532c7a21e3f6b7df3aad10d7bdfbb7a812ae6c7.err \
|
||||
$(srcdir)/%reldir%/test_sql.sh_5532c7a21e3f6b7df3aad10d7bdfbb7a812ae6c7.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_56047c9470e515bc3e3709354c01e5d50462cde7.err \
|
||||
$(srcdir)/%reldir%/test_sql.sh_56047c9470e515bc3e3709354c01e5d50462cde7.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_57427f3c4b4ec785ffff7c5802c10db0d3e547cf.err \
|
||||
$(srcdir)/%reldir%/test_sql.sh_57427f3c4b4ec785ffff7c5802c10db0d3e547cf.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_57edc93426e6767aa44ab2356c55327553dcdc8d.err \
|
||||
@ -670,8 +668,8 @@ EXPECTED_FILES = \
|
||||
$(srcdir)/%reldir%/test_sql.sh_c73dec2706fc0b9a124f5da3a83f40d8d3255beb.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_c7e1dbf4605914720b55787785abfafdf2c4178a.err \
|
||||
$(srcdir)/%reldir%/test_sql.sh_c7e1dbf4605914720b55787785abfafdf2c4178a.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_cc77a633a66d1778705a34e3657737547b3fb08d.err \
|
||||
$(srcdir)/%reldir%/test_sql.sh_cc77a633a66d1778705a34e3657737547b3fb08d.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_d4d540f0ef7e34b693fc72078d1cf2e069f86d81.err \
|
||||
$(srcdir)/%reldir%/test_sql.sh_d4d540f0ef7e34b693fc72078d1cf2e069f86d81.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_dd540973a0dc86320d84706845a15608196ae5be.err \
|
||||
$(srcdir)/%reldir%/test_sql.sh_dd540973a0dc86320d84706845a15608196ae5be.out \
|
||||
$(srcdir)/%reldir%/test_sql.sh_e70dc7d2b686c7f91c2b41b10f3920c50f3ea405.err \
|
||||
|
@ -0,0 +1,4 @@
|
||||
[1m[4m[7mtotal [0m[1m[4m min(log_time) [0m[1m[4mduration [0m[1m[4mlog_formats [0m[1m[4m log_msg_format [0m
|
||||
[1m[7m 2[0m[7m [0m[7m2023-04-28 06:53:55.000[0m[7m [0m[7m [0m[7m [0m[7msyslog_log [0m[7m [0m[7mRegistering new address record for # on # [0m
|
||||
[1m[7m 2[0m[7m [0m[7m2023-04-28 06:53:55.000[0m[7m [0m[7m [0m[7m [0m[7msyslog_log [0m[7m [0m[7mNew relevant interface # for # [0m
|
||||
[1m[7m 2[0m[1m[7m [0m[1m[7m2023-04-28 06:53:55.000[0m[1m[7m [0m[1m[7m [0m[1m[7m [0m[1m[7msyslog_log [0m[1m[7m [0m[1m[7mJoining # multicast group on interface # with address #[0m[1m [0m
|
@ -1103,3 +1103,7 @@ run_cap_test ${lnav_test} -n \
|
||||
|
||||
run_cap_test ${lnav_test} -Nn \
|
||||
-c ";select *,case match_index when 2 then replicate('abc', 1000) else '' end from regexp_capture_into_json('10;50;50;50;', '(\d+);')"
|
||||
|
||||
run_cap_test ${lnav_test} -n \
|
||||
-c ";.msgformats" \
|
||||
${test_dir}/logfile_for_join.0
|
||||
|
Loading…
Reference in New Issue
Block a user