[log_format] gracefully handle a misconfigured log format

Fixes #742
This commit is contained in:
Timothy Stack 2020-08-27 13:42:10 -07:00
parent d0f2f9e800
commit 4fa4a7057b
6 changed files with 27 additions and 7 deletions

View File

@ -39,6 +39,7 @@
#include <string>
#include <vector>
#include "base/lnav_log.hh"
#include "base/intern_string.hh"
/**
@ -158,21 +159,29 @@ typedef string_attr_type *string_attr_type_t;
struct string_attr {
string_attr(const struct line_range &lr, string_attr_type_t type, void *val)
: sa_range(lr), sa_type(type) {
require(lr.is_valid());
require(type);
this->sa_value.sav_ptr = val;
};
string_attr(const struct line_range &lr, string_attr_type_t type, intern_string_t val)
: sa_range(lr), sa_type(type) {
require(lr.is_valid());
require(type);
this->sa_value.sav_ptr = val.unwrap();
};
string_attr(const struct line_range &lr, string_attr_type_t type, int64_t val = 0)
: sa_range(lr), sa_type(type) {
require(lr.is_valid());
require(type);
this->sa_value.sav_int = val;
};
string_attr(const struct line_range &lr, string_attr_type_t type, string_attr_value_t val)
: sa_range(lr), sa_type(type), sa_value(val) {
require(lr.is_valid());
require(type);
};
string_attr() : sa_type(NULL) { };

View File

@ -814,7 +814,7 @@
:open *path*
^^^^^^^^^^^^
Open the given file(s) or URLs in lnav
Open the given file(s) in lnav
**Parameters:**

View File

@ -769,9 +769,11 @@ void external_log_format::annotate(uint64_t line_number, shared_buffer_ref &line
if (!pat.p_module_format) {
cap = pc[pat.p_timestamp_field_index];
lr.lr_start = cap->c_begin;
lr.lr_end = cap->c_end;
sa.emplace_back(lr, &logline::L_TIMESTAMP);
if (cap->is_valid()) {
lr.lr_start = cap->c_begin;
lr.lr_end = cap->c_end;
sa.emplace_back(lr, &logline::L_TIMESTAMP);
}
if (pat.p_module_field_index != -1) {
module_cap = pc[pat.p_module_field_index];

View File

@ -209,8 +209,15 @@ void logfile_sub_source::text_value_for_line(textview_curses &tc,
sbr.share(this->lss_share_manager,
(char *)this->lss_token_value.c_str(), this->lss_token_value.size());
format->annotate(line, sbr, this->lss_token_attrs, this->lss_token_values,
false);
if (this->lss_token_line->is_continued()) {
this->lss_token_attrs.emplace_back(
line_range{0, (int) this->lss_token_value.length()},
&textview_curses::SA_BODY);
} else {
format->annotate(line, sbr, this->lss_token_attrs,
this->lss_token_values,
false);
}
if (this->lss_token_line->get_sub_offset() != 0) {
this->lss_token_attrs.clear();
}

View File

@ -115,6 +115,7 @@ string_attr_type textview_curses::SA_ORIGINAL_LINE("original_line");
string_attr_type textview_curses::SA_BODY("body");
string_attr_type textview_curses::SA_HIDDEN("hidden");
string_attr_type textview_curses::SA_FORMAT("format");
string_attr_type textview_curses::SA_REMOVED("removed");
textview_curses::textview_curses()
: tc_sub_source(NULL),
@ -356,7 +357,7 @@ void textview_curses::textview_value_for_row(vis_line_t row,
for_each(sa.begin(), sa.end(), [&] (string_attr &attr) {
if (attr.sa_type == &VC_STYLE &&
attr.sa_range.lr_start == lr.lr_start) {
attr.sa_type = nullptr;
attr.sa_type = &SA_REMOVED;
}
});
}

View File

@ -588,6 +588,7 @@ public:
static string_attr_type SA_BODY;
static string_attr_type SA_HIDDEN;
static string_attr_type SA_FORMAT;
static string_attr_type SA_REMOVED;
textview_curses();
virtual ~textview_curses();