mirror of
https://github.com/tstack/lnav.git
synced 2024-09-11 13:05:51 +03:00
[log_format] check that patterns have a timestamp capture
This commit is contained in:
parent
3f4c572368
commit
6334ad299c
@ -931,12 +931,18 @@ external_log_format::scan(logfile& lf,
|
||||
ts = string_fragment::from_bytes(combined_datetime_buf, ts_str_len);
|
||||
}
|
||||
|
||||
if ((last = this->lf_date_time.scan(ts->data(),
|
||||
ts->length(),
|
||||
this->get_timestamp_formats(),
|
||||
&log_time_tm,
|
||||
log_tv))
|
||||
== nullptr)
|
||||
auto level = this->convert_level(
|
||||
level_cap.value_or(string_fragment::invalid()), &sbc);
|
||||
|
||||
if (!ts) {
|
||||
level = log_level_t::LEVEL_INVALID;
|
||||
} else if ((last
|
||||
= this->lf_date_time.scan(ts->data(),
|
||||
ts->length(),
|
||||
this->get_timestamp_formats(),
|
||||
&log_time_tm,
|
||||
log_tv))
|
||||
== nullptr)
|
||||
{
|
||||
this->lf_date_time.unlock();
|
||||
if ((last = this->lf_date_time.scan(ts->data(),
|
||||
@ -950,9 +956,6 @@ external_log_format::scan(logfile& lf,
|
||||
}
|
||||
}
|
||||
|
||||
auto level = this->convert_level(
|
||||
level_cap.value_or(string_fragment::invalid()), &sbc);
|
||||
|
||||
this->lf_timestamp_flags = log_time_tm.et_flags;
|
||||
|
||||
if (!((log_time_tm.et_flags & ETF_DAY_SET)
|
||||
@ -2276,6 +2279,16 @@ external_log_format::build(std::vector<lnav::console::user_message>& errors)
|
||||
}
|
||||
}
|
||||
|
||||
if (!pat.p_module_format && pat.p_timestamp_field_index == -1) {
|
||||
errors.emplace_back(
|
||||
lnav::console::user_message::error(
|
||||
attr_line_t("invalid pattern: ")
|
||||
.append_quoted(lnav::roles::symbol(pat.p_config_path)))
|
||||
.with_reason("no timestamp capture found in the pattern")
|
||||
.with_snippets(this->get_snippets())
|
||||
.with_help("all log messages need a timestamp"));
|
||||
}
|
||||
|
||||
if (!this->elf_level_field.empty() && pat.p_level_field_index == -1) {
|
||||
log_warning("%s:level field '%s' not found in pattern",
|
||||
pat.p_config_path.c_str(),
|
||||
|
@ -167,6 +167,10 @@
|
||||
[33mreason[0m: pattern does not match any samples
|
||||
[36m --> [0m[1m{test_dir}/bad-config/formats/invalid-sample/format.json[0m:7
|
||||
[36m =[0m [36mhelp[0m: every pattern should have at least one sample that it matches
|
||||
[1m[31m✘ error[0m: invalid pattern: “[1m/invalid_props_log/regex/std[0m”
|
||||
[1m[31mreason[0m: no timestamp capture found in the pattern
|
||||
[36m --> [0m[1m{test_dir}/bad-config/formats/invalid-properties/format.json[0m:4
|
||||
[36m =[0m [36mhelp[0m: all log messages need a timestamp
|
||||
[33m⚠ warning[0m: invalid value “[1m/invalid_props_log/value/non-existent[0m”
|
||||
[33mreason[0m: no patterns have a capture named “non-existent”
|
||||
[36m --> [0m[1m{test_dir}/bad-config/formats/invalid-properties/format.json[0m:4
|
||||
|
@ -58,6 +58,10 @@
|
||||
[1m[31m✘ error[0m: “[1mfoobar_log[0m” is not a valid log format
|
||||
[1m[31mreason[0m: log message samples must be included in a format definition
|
||||
[36m --> [0m[1m{test_dir}/bad-config-json/formats/invalid-json/format.json[0m:3
|
||||
[1m[31m✘ error[0m: invalid pattern: “[1m/invalid_key_log/regex/foo[0m”
|
||||
[1m[31mreason[0m: no timestamp capture found in the pattern
|
||||
[36m --> [0m[1m{test_dir}/bad-config-json/formats/invalid-key/format.json[0m:4
|
||||
[36m =[0m [36mhelp[0m: all log messages need a timestamp
|
||||
[1m[31m✘ error[0m: “[1minvalid_key_log[0m” is not a valid log format
|
||||
[1m[31mreason[0m: structured logs cannot have regexes
|
||||
[36m --> [0m[1m{test_dir}/bad-config-json/formats/invalid-key/format.json[0m:4
|
||||
|
Loading…
Reference in New Issue
Block a user