mirror of
https://github.com/tstack/lnav.git
synced 2024-09-11 13:05:51 +03:00
[opid] add opids set by the user to session exports
This commit is contained in:
parent
a90fe01eab
commit
fdecf28699
@ -2768,8 +2768,8 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
|
||||
}
|
||||
|
||||
if (lnav_data.ld_flags & LNF_SECURE_MODE) {
|
||||
if ((sqlite3_set_authorizer(
|
||||
lnav_data.ld_db.in(), sqlite_authorizer, nullptr))
|
||||
if (sqlite3_set_authorizer(
|
||||
lnav_data.ld_db.in(), sqlite_authorizer, nullptr)
|
||||
!= SQLITE_OK)
|
||||
{
|
||||
fprintf(stderr, "error: unable to attach sqlite authorizer\n");
|
||||
|
@ -71,7 +71,8 @@ static const char* LOG_FOOTER_COLUMNS = R"(
|
||||
log_tags TEXT, -- A JSON list of tags for this message
|
||||
log_annotations TEXT, -- A JSON object of annotations for this messages
|
||||
log_filters TEXT, -- A JSON list of filter IDs that matched this message
|
||||
log_opid TEXT HIDDEN, -- The message's OPID
|
||||
log_opid TEXT HIDDEN, -- The message's OPID from the log message or user
|
||||
log_user_opid TEXT HIDDEN, -- The message's OPID as set by the user
|
||||
log_format TEXT HIDDEN, -- The name of the log file format
|
||||
log_format_regex TEXT HIDDEN, -- The name of the regex used to parse this log message
|
||||
log_time_msecs INTEGER HIDDEN, -- The adjusted timestamp for the log message as the number of milliseconds from the epoch
|
||||
@ -93,6 +94,7 @@ enum class log_footer_columns : uint32_t {
|
||||
annotations,
|
||||
filters,
|
||||
opid,
|
||||
user_opid,
|
||||
format,
|
||||
format_regex,
|
||||
time_msecs,
|
||||
@ -880,6 +882,25 @@ vt_column(sqlite3_vtab_cursor* cur, sqlite3_context* ctx, int col)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case log_footer_columns::user_opid: {
|
||||
if (vc->line_values.lvv_values.empty()) {
|
||||
vc->cache_msg(lf, ll);
|
||||
require(vc->line_values.lvv_sbr.get_data()
|
||||
!= nullptr);
|
||||
vt->vi->extract(lf, line_number, vc->line_values);
|
||||
}
|
||||
|
||||
if (vc->line_values.lvv_opid_value
|
||||
&& vc->line_values.lvv_opid_provenance
|
||||
== logline_value_vector::opid_provenance::user)
|
||||
{
|
||||
to_sqlite(ctx,
|
||||
vc->line_values.lvv_opid_value.value());
|
||||
} else {
|
||||
sqlite3_result_null(ctx);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case log_footer_columns::format: {
|
||||
auto format_name = lf->get_format_name();
|
||||
sqlite3_result_text(ctx,
|
||||
@ -1244,8 +1265,8 @@ log_cursor::update(unsigned char op, vis_line_t vl, constraint_t cons)
|
||||
}
|
||||
}
|
||||
|
||||
log_cursor::string_constraint::string_constraint(unsigned char op,
|
||||
std::string value)
|
||||
log_cursor::string_constraint::
|
||||
string_constraint(unsigned char op, std::string value)
|
||||
: sc_op(op), sc_value(std::move(value))
|
||||
{
|
||||
if (op == SQLITE_INDEX_CONSTRAINT_REGEXP) {
|
||||
@ -1498,7 +1519,8 @@ vt_filter(sqlite3_vtab_cursor* p_vtc,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case log_footer_columns::opid: {
|
||||
case log_footer_columns::opid:
|
||||
case log_footer_columns::user_opid: {
|
||||
if (sqlite3_value_type(argv[lpc]) != SQLITE3_TEXT) {
|
||||
continue;
|
||||
}
|
||||
@ -1862,7 +1884,8 @@ vt_best_index(sqlite3_vtab* tab, sqlite3_index_info* p_info)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case log_footer_columns::opid: {
|
||||
case log_footer_columns::opid:
|
||||
case log_footer_columns::user_opid: {
|
||||
if (op == SQLITE_INDEX_CONSTRAINT_EQ) {
|
||||
argvInUse += 1;
|
||||
indexes.push_back(constraint);
|
||||
@ -1992,10 +2015,18 @@ vt_update(sqlite3_vtab* tab,
|
||||
argc, argv, 2 + vt->footer_index(log_footer_columns::tags));
|
||||
const auto log_annos = from_sqlite<std::optional<string_fragment>>()(
|
||||
argc, argv, 2 + vt->footer_index(log_footer_columns::annotations));
|
||||
const auto log_opid = from_sqlite<std::optional<string_fragment>>()(
|
||||
auto log_opid = from_sqlite<std::optional<string_fragment>>()(
|
||||
argc, argv, 2 + vt->footer_index(log_footer_columns::opid));
|
||||
const auto log_user_opid
|
||||
= from_sqlite<std::optional<string_fragment>>()(
|
||||
argc,
|
||||
argv,
|
||||
2 + vt->footer_index(log_footer_columns::user_opid));
|
||||
bookmark_metadata tmp_bm;
|
||||
|
||||
if (log_user_opid) {
|
||||
log_opid = log_user_opid;
|
||||
}
|
||||
if (log_tags) {
|
||||
std::vector<lnav::console::user_message> errors;
|
||||
yajlpp_parse_context ypc(vt->vi->get_tags_name(), &tags_handler);
|
||||
@ -2200,9 +2231,8 @@ progress_callback(void* ptr)
|
||||
return retval;
|
||||
}
|
||||
|
||||
log_vtab_manager::log_vtab_manager(sqlite3* memdb,
|
||||
textview_curses& tc,
|
||||
logfile_sub_source& lss)
|
||||
log_vtab_manager::
|
||||
log_vtab_manager(sqlite3* memdb, textview_curses& tc, logfile_sub_source& lss)
|
||||
: vm_db(memdb), vm_textview(tc), vm_source(lss)
|
||||
{
|
||||
sqlite3_create_module(
|
||||
@ -2212,7 +2242,8 @@ log_vtab_manager::log_vtab_manager(sqlite3* memdb,
|
||||
sqlite3_progress_handler(memdb, 32, progress_callback, nullptr);
|
||||
}
|
||||
|
||||
log_vtab_manager::~log_vtab_manager()
|
||||
log_vtab_manager::~
|
||||
log_vtab_manager()
|
||||
{
|
||||
while (!this->vm_impls.empty()) {
|
||||
auto first_name = this->vm_impls.begin()->first;
|
||||
|
@ -43,6 +43,7 @@ struct log_message_session_state {
|
||||
std::optional<std::string> lmss_comment;
|
||||
std::optional<std::string> lmss_tags;
|
||||
std::optional<std::string> lmss_annotations;
|
||||
std::optional<std::string> lmss_opid;
|
||||
std::string lmss_hash;
|
||||
};
|
||||
|
||||
@ -59,7 +60,8 @@ struct from_sqlite<log_message_session_state> {
|
||||
from_sqlite<std::optional<std::string>>()(argc, argv, argi + 3),
|
||||
from_sqlite<std::optional<std::string>>()(argc, argv, argi + 4),
|
||||
from_sqlite<std::optional<std::string>>()(argc, argv, argi + 5),
|
||||
from_sqlite<std::string>()(argc, argv, argi + 6),
|
||||
from_sqlite<std::optional<std::string>>()(argc, argv, argi + 6),
|
||||
from_sqlite<std::string>()(argc, argv, argi + 7),
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -180,12 +182,13 @@ export_to(FILE* file)
|
||||
static auto& lnav_db = injector::get<auto_sqlite3&>();
|
||||
|
||||
static const char* BOOKMARK_QUERY = R"(
|
||||
SELECT log_time_msecs, log_format, log_mark, log_comment, log_tags, log_annotations, log_line_hash
|
||||
SELECT log_time_msecs, log_format, log_mark, log_comment, log_tags, log_annotations, log_user_opid, log_line_hash
|
||||
FROM all_logs
|
||||
WHERE log_mark = 1 OR
|
||||
log_comment IS NOT NULL OR
|
||||
log_tags IS NOT NULL OR
|
||||
log_annotations IS NOT NULL
|
||||
log_annotations IS NOT NULL OR
|
||||
(log_user_opid IS NOT NULL AND log_user_opid != '')
|
||||
)";
|
||||
|
||||
static const char* FILTER_QUERY = R"(
|
||||
@ -325,7 +328,8 @@ SELECT content_id, format, time_offset FROM lnav_file
|
||||
"SET log_mark = {}, "
|
||||
"log_comment = {}, "
|
||||
"log_tags = {}, "
|
||||
"log_annotations = {} "
|
||||
"log_annotations = {}, "
|
||||
"log_opid = {} "
|
||||
"WHERE log_time_msecs = {} AND "
|
||||
"log_format = {} AND "
|
||||
"log_line_hash = {}\n"),
|
||||
@ -333,6 +337,7 @@ SELECT content_id, format, time_offset FROM lnav_file
|
||||
sqlitepp::quote(lmss.lmss_comment).in(),
|
||||
sqlitepp::quote(lmss.lmss_tags).in(),
|
||||
sqlitepp::quote(lmss.lmss_annotations).in(),
|
||||
sqlitepp::quote(lmss.lmss_opid).in(),
|
||||
lmss.lmss_time_msecs,
|
||||
sqlitepp::quote(lmss.lmss_format).in(),
|
||||
sqlitepp::quote(lmss.lmss_hash).in());
|
||||
|
@ -21,7 +21,7 @@
|
||||
# comments, and tags that were added in the session.
|
||||
|
||||
;SELECT total_changes() AS before_mark_changes
|
||||
;UPDATE all_logs SET log_mark = 1, log_comment = NULL, log_tags = NULL, log_annotations = NULL WHERE log_time_msecs = 1248130769000 AND log_format = 'access_log' AND log_line_hash = 'v1:b05c1bdfe75cde41e151c89087e31951'
|
||||
;UPDATE all_logs SET log_mark = 1, log_comment = NULL, log_tags = NULL, log_annotations = NULL, log_opid = NULL WHERE log_time_msecs = 1248130769000 AND log_format = 'access_log' AND log_line_hash = 'v1:b05c1bdfe75cde41e151c89087e31951'
|
||||
|
||||
;SELECT 1 - (total_changes() - $before_mark_changes) AS failed_mark_changes
|
||||
;SELECT echoln(printf('%sERROR%s: failed to restore %d bookmarks',
|
||||
|
@ -20,7 +20,7 @@
|
||||
# comments, and tags that were added in the session.
|
||||
|
||||
;SELECT total_changes() AS before_mark_changes
|
||||
;UPDATE all_logs SET log_mark = 0, log_comment = NULL, log_tags = NULL, log_annotations = '{"org.lnav.test":"Hello, <span style=\"color: #f00\">World</span>!\n"}' WHERE log_time_msecs = 1248130766000 AND log_format = 'access_log' AND log_line_hash = 'v1:3f7e0f10f2473f83b2b4eacccfc9b4e2'
|
||||
;UPDATE all_logs SET log_mark = 0, log_comment = NULL, log_tags = NULL, log_annotations = '{"org.lnav.test":"Hello, <span style=\"color: #f00\">World</span>!\n"}', log_opid = NULL WHERE log_time_msecs = 1248130766000 AND log_format = 'access_log' AND log_line_hash = 'v1:3f7e0f10f2473f83b2b4eacccfc9b4e2'
|
||||
|
||||
;SELECT 1 - (total_changes() - $before_mark_changes) AS failed_mark_changes
|
||||
;SELECT echoln(printf('%sERROR%s: failed to restore %d bookmarks',
|
||||
|
Loading…
Reference in New Issue
Block a user