diff --git a/src/log_format.cc b/src/log_format.cc index ac6a8e05..0e35b646 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -146,7 +146,8 @@ bool log_format::next_format(pcre_format *fmt, int &index, int &locked_index) return retval; } -const char *log_format::log_scanf(const char *line, +const char *log_format::log_scanf(uint32_t line_number, + const char *line, size_t len, pcre_format *fmt, const char *time_fmt[], @@ -184,7 +185,15 @@ const char *log_format::log_scanf(const char *line, if (retval) { if (curr_fmt != pat_index) { - this->lf_pattern_locks.emplace_back(0, curr_fmt); + uint32_t lock_line; + + if (this->lf_pattern_locks.empty()) { + lock_line = 0; + } else { + lock_line = line_number; + } + + this->lf_pattern_locks.emplace_back(lock_line, curr_fmt); } this->lf_timestamp_flags = tm_out->et_flags; done = true; @@ -672,8 +681,15 @@ log_format::scan_result_t external_log_format::scan(nonstd::optional dst.emplace_back(offset, log_tv, level, mod_index, opid); if (orig_lock != curr_fmt) { + uint32_t lock_line; + log_debug("changing pattern lock %d -> %d", orig_lock, curr_fmt); - this->lf_pattern_locks.emplace_back(dst.size() - 1, curr_fmt); + if (this->lf_pattern_locks.empty()) { + lock_line = 0; + } else { + lock_line = dst.size() - 1; + } + this->lf_pattern_locks.emplace_back(lock_line, curr_fmt); } return log_format::SCAN_MATCH; } diff --git a/src/log_format.hh b/src/log_format.hh index 4c28e2d4..b57cd7ba 100644 --- a/src/log_format.hh +++ b/src/log_format.hh @@ -830,7 +830,8 @@ protected: static bool next_format(pcre_format *fmt, int &index, int &locked_index); - const char *log_scanf(const char *line, + const char *log_scanf(uint32_t line_number, + const char *line, size_t len, pcre_format *fmt, const char *time_fmt[], diff --git a/src/log_format_impls.cc b/src/log_format_impls.cc index a8ae0b9e..fb0a764b 100644 --- a/src/log_format_impls.cc +++ b/src/log_format_impls.cc @@ -148,6 +148,7 @@ class generic_log_format : public log_format { const char *last_pos; if ((last_pos = this->log_scanf( + dst.size(), sbr.get_data(), sbr.length(), get_pcre_log_formats(), diff --git a/test/Makefile.am b/test/Makefile.am index 99155810..33a3ac3c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -227,6 +227,7 @@ dist_noinst_DATA = \ logfile_generic.0 \ logfile_generic.1 \ logfile_generic.2 \ + logfile_generic_with_header.0 \ logfile_glog.0 \ logfile_haproxy.0 \ logfile_journald.json \ @@ -247,6 +248,7 @@ dist_noinst_DATA = \ logfile_syslog.2 \ logfile_syslog_fr.0 \ logfile_syslog_with_access_log.0 \ + logfile_syslog_with_header.0 \ logfile_syslog_with_mixed_times.0 \ logfile_tai64n.0 \ logfile_tcf.0 \ diff --git a/test/logfile_generic_with_header.0 b/test/logfile_generic_with_header.0 new file mode 100644 index 00000000..bea5673e --- /dev/null +++ b/test/logfile_generic_with_header.0 @@ -0,0 +1,4 @@ +Header1: abc +Header2: def +2012-07-02 10:22:40,672:DEBUG:foo bar baz +2014-10-08 16:56:38,344:WARN:foo bar baz \ No newline at end of file diff --git a/test/logfile_syslog_with_header.0 b/test/logfile_syslog_with_header.0 new file mode 100644 index 00000000..8f22c162 --- /dev/null +++ b/test/logfile_syslog_with_header.0 @@ -0,0 +1,6 @@ +Header1: abc +Header2: def +Nov 3 09:23:38 veridian automount[7998]: lookup(file): lookup for foobar failed +Nov 3 09:23:38 veridian automount[16442]: attempting to mount entry /auto/opt +Nov 3 09:23:38 veridian automount[7999]: lookup(file): lookup for opt failed +Nov 3 09:47:02 veridian sudo: timstack : TTY=pts/6 ; PWD=/auto/wstimstack/rpms/lbuild/test ; USER=root ; COMMAND=/usr/bin/tail /var/log/messages diff --git a/test/test_logfile.sh b/test/test_logfile.sh index e86c7f24..8141eb02 100644 --- a/test/test_logfile.sh +++ b/test/test_logfile.sh @@ -378,6 +378,28 @@ count(*) 17 EOF +run_test ${lnav_test} -n \ + ${srcdir}/logfile_syslog_with_header.0 + +check_output "multi-pattern logs don't work?" <