Skip to content

Commit

Permalink
[lnav_piper_log] generic_log should have a higher priority
Browse files Browse the repository at this point in the history
  • Loading branch information
tstack committed Mar 2, 2025
1 parent 2df29dc commit 26a763b
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 251 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Bug Fixes:
So, a light background with a dark foreground will be respected.
* Improved performance for compressed files.
* Copying a column with a text value in the DB overlay view.
* Generic logs read from stdin or exec'd were not working properly.
## lnav v0.12.4
Expand Down
18 changes: 11 additions & 7 deletions src/log_format_impls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <algorithm>
#include <chrono>
#include <memory>
#include <utility>

#include "log_format.hh"
Expand Down Expand Up @@ -74,13 +75,15 @@ class piper_log_format : public log_format {
return scan_no_match{"not a piper capture"};
}

static constexpr int TIMESTAMP_SIZE = 28;

void annotate(logfile* lf,
uint64_t line_number,
string_attrs_t& sa,
logline_value_vector& values,
bool annotate_module) const override
{
auto lr = line_range{0, 0};
auto lr = line_range{0, TIMESTAMP_SIZE};
sa.emplace_back(lr, L_TIMESTAMP.value());
log_format::annotate(lf, line_number, sa, values, annotate_module);
}
Expand All @@ -89,7 +92,7 @@ class piper_log_format : public log_format {
shared_buffer_ref& sbr,
bool full_message) override
{
this->plf_cached_line.resize(32);
this->plf_cached_line.resize(TIMESTAMP_SIZE);
auto tlen = sql_strftime(this->plf_cached_line.data(),
this->plf_cached_line.size(),
ll.get_timeval(),
Expand Down Expand Up @@ -127,7 +130,7 @@ class piper_log_format : public log_format {
auto retval = std::make_shared<piper_log_format>(*this);

retval->lf_specialized = true;
retval->lf_timestamp_flags |= ETF_ZONE_SET;
retval->lf_timestamp_flags |= ETF_ZONE_SET | ETF_MICROS_SET;
return retval;
}

Expand Down Expand Up @@ -193,8 +196,8 @@ class generic_log_format : public log_format {
shared_buffer_ref& sbr,
scan_batch_context& sbc) override
{
struct exttm log_time;
struct timeval log_tv;
exttm log_time;
timeval log_tv;
string_fragment ts;
std::optional<string_fragment> level;
const char* last_pos;
Expand All @@ -221,7 +224,7 @@ class generic_log_format : public log_format {
&level))
!= nullptr)
{
log_level_t level_val = log_level_t::LEVEL_UNKNOWN;
auto level_val = log_level_t::LEVEL_UNKNOWN;
if (level) {
level_val = string2level(level->data(), level->length());
}
Expand Down Expand Up @@ -258,7 +261,7 @@ class generic_log_format : public log_format {
}

dst.emplace_back(li.li_file_range.fr_offset, log_tv, level_val);
return scan_match{0};
return scan_match{5};
}

return scan_no_match{"no patterns matched"};
Expand Down Expand Up @@ -2114,6 +2117,7 @@ class logfmt_format : public log_format {
if (kvp.first == "time" || kvp.first == "ts") {
sa.emplace_back(value_lr, L_TIMESTAMP.value());
} else if (kvp.first == "level") {
sa.emplace_back(value_lr, L_LEVEL.value());
} else if (kvp.first == "msg") {
sa.emplace_back(value_lr, SA_BODY.value());
} else if (kvp.second.is<logfmt::parser::quoted_value>()
Expand Down
125 changes: 69 additions & 56 deletions src/logfile_sub_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,58 +422,29 @@ logfile_sub_source::text_value_for_line(textview_curses& tc,
&& this->tss_view->get_selection() == row)
{
buffer[this->lss_time_column_size] = ' ';
this->lss_time_column_size += 1;
buffer[this->lss_time_column_size + 1] = ' ';
this->lss_time_column_size += 2;
} else {
constexpr char block[] = "\u258c";
constexpr char block[] = "\u258c ";

strncpy(
&buffer[this->lss_time_column_size], block, sizeof(block));
this->lss_time_column_size += sizeof(block) - 1;
}
if (time_attr->sa_range.lr_start != 0) {
buffer[this->lss_time_column_size] = ' ';
this->lss_time_column_size += 1;
this->lss_time_column_padding = 1;
} else {
this->lss_time_column_padding = 0;
}
value_out.insert(1, buffer, this->lss_time_column_size);
}
if (format->lf_level_hideable) {
auto level_attr = find_string_attr(this->lss_token_attrs, &L_LEVEL);
if (level_attr != this->lss_token_attrs.end()) {
ui_icon_t icon;
switch (this->lss_token_line->get_msg_level()) {
case LEVEL_TRACE:
icon = ui_icon_t::log_level_trace;
break;
case LEVEL_DEBUG:
case LEVEL_DEBUG2:
case LEVEL_DEBUG3:
case LEVEL_DEBUG4:
case LEVEL_DEBUG5:
icon = ui_icon_t::log_level_debug;
break;
case LEVEL_INFO:
icon = ui_icon_t::log_level_info;
break;
case LEVEL_STATS:
icon = ui_icon_t::log_level_stats;
break;
case LEVEL_NOTICE:
icon = ui_icon_t::log_level_notice;
break;
case LEVEL_WARNING:
icon = ui_icon_t::log_level_warning;
break;
case LEVEL_ERROR:
icon = ui_icon_t::log_level_error;
break;
case LEVEL_CRITICAL:
icon = ui_icon_t::log_level_critical;
break;
case LEVEL_FATAL:
icon = ui_icon_t::log_level_fatal;
break;
default:
icon = ui_icon_t::hidden;
break;
}
this->lss_token_attrs.emplace_back(level_attr->sa_range,
SA_HIDDEN.value(icon));
SA_REPLACED.value());
}
}
} else if (this->lss_line_context < line_context_t::none) {
Expand Down Expand Up @@ -650,18 +621,60 @@ logfile_sub_source::text_attrs_for_line(textview_curses& lv,
this->lss_token_file->get_filename())));
} else if (this->lss_time_column_size > 0) {
shift_string_attrs(value_out, 1, this->lss_time_column_size);

ui_icon_t icon;
switch (this->lss_token_line->get_msg_level()) {
case LEVEL_TRACE:
icon = ui_icon_t::log_level_trace;
break;
case LEVEL_DEBUG:
case LEVEL_DEBUG2:
case LEVEL_DEBUG3:
case LEVEL_DEBUG4:
case LEVEL_DEBUG5:
icon = ui_icon_t::log_level_debug;
break;
case LEVEL_INFO:
icon = ui_icon_t::log_level_info;
break;
case LEVEL_STATS:
icon = ui_icon_t::log_level_stats;
break;
case LEVEL_NOTICE:
icon = ui_icon_t::log_level_notice;
break;
case LEVEL_WARNING:
icon = ui_icon_t::log_level_warning;
break;
case LEVEL_ERROR:
icon = ui_icon_t::log_level_error;
break;
case LEVEL_CRITICAL:
icon = ui_icon_t::log_level_critical;
break;
case LEVEL_FATAL:
icon = ui_icon_t::log_level_fatal;
break;
default:
icon = ui_icon_t::hidden;
break;
}
auto extra_space_size = this->lss_time_column_padding;
lr.lr_start = 1 + this->lss_time_column_size - 1 - extra_space_size;
lr.lr_end = 1 + this->lss_time_column_size - extra_space_size;
value_out.emplace_back(lr, VC_ICON.value(icon));
if (this->tss_view->is_selectable()
&& this->tss_view->get_selection() != row)
{
lr.lr_start = 1;
lr.lr_end = 1 + this->lss_time_column_size - 1;
lr.lr_end = 1 + this->lss_time_column_size - 2 - extra_space_size;
value_out.emplace_back(lr, VC_ROLE.value(role_t::VCR_TIME_COLUMN));
if (this->lss_token_line->is_time_skewed()) {
value_out.emplace_back(lr,
VC_ROLE.value(role_t::VCR_SKEWED_TIME));
}
lr.lr_start = 1 + this->lss_time_column_size - 1;
lr.lr_end = 1 + this->lss_time_column_size;
lr.lr_start = 1 + this->lss_time_column_size - 2 - extra_space_size;
lr.lr_end = 1 + this->lss_time_column_size - 1 - extra_space_size;
value_out.emplace_back(
lr, VC_ROLE.value(role_t::VCR_TIME_COLUMN_TO_TEXT));
}
Expand Down Expand Up @@ -722,21 +735,21 @@ logfile_sub_source::text_attrs_for_line(textview_curses& lv,
}
}

if (this->lss_token_file->is_time_adjusted()) {
auto time_range = find_string_attr_range(value_out, &L_TIMESTAMP);

if (time_range.lr_end != -1) {
value_out.emplace_back(time_range,
VC_ROLE.value(role_t::VCR_ADJUSTED_TIME));
}
}
if (this->lss_time_column_size == 0) {
if (this->lss_token_file->is_time_adjusted()) {
auto time_range = find_string_attr_range(value_out, &L_TIMESTAMP);

if (this->lss_token_line->is_time_skewed()) {
auto time_range = find_string_attr_range(value_out, &L_TIMESTAMP);
if (time_range.lr_end != -1) {
value_out.emplace_back(
time_range, VC_ROLE.value(role_t::VCR_ADJUSTED_TIME));
}
} else if (this->lss_token_line->is_time_skewed()) {
auto time_range = find_string_attr_range(value_out, &L_TIMESTAMP);

if (time_range.lr_end != -1) {
value_out.emplace_back(time_range,
VC_ROLE.value(role_t::VCR_SKEWED_TIME));
if (time_range.lr_end != -1) {
value_out.emplace_back(time_range,
VC_ROLE.value(role_t::VCR_SKEWED_TIME));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/logfile_sub_source.hh
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ private:
int lss_token_meta_line{-1};
int lss_token_meta_size{0};
size_t lss_time_column_size{0};
size_t lss_time_column_padding{0};
logline_value_vector lss_token_values;
int lss_token_shift_start{0};
int lss_token_shift_size{0};
Expand Down
Loading

0 comments on commit 26a763b

Please sign in to comment.