summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--logd/src/logd/legacy_forwarder.cpp7
-rw-r--r--logd/src/logd/watcher.cpp2
-rw-r--r--logd/src/tests/legacy_forwarder/legacy_forwarder_test.cpp4
-rw-r--r--logd/src/tests/watcher/watcher_test.cpp3
-rw-r--r--vespalog/src/vespa/log/log_message.cpp25
5 files changed, 26 insertions, 15 deletions
diff --git a/logd/src/logd/legacy_forwarder.cpp b/logd/src/logd/legacy_forwarder.cpp
index c0f74d205e7..851e4458f77 100644
--- a/logd/src/logd/legacy_forwarder.cpp
+++ b/logd/src/logd/legacy_forwarder.cpp
@@ -11,6 +11,7 @@
#include <vespa/vespalib/util/stringfmt.h>
#include <fcntl.h>
#include <unistd.h>
+#include <sstream>
#include <vespa/log/log.h>
LOG_SETUP("");
@@ -126,12 +127,12 @@ void
LegacyForwarder::forwardLine(std::string_view line)
{
assert(_logserver_fd >= 0);
- assert (line.size() > 0);
assert (line.size() < 1024*1024);
- assert (line[line.size() - 1] == '\n');
if (parseLine(line)) {
- forwardText(line.data(), line.size());
+ std::ostringstream line_copy;
+ line_copy << line << std::endl;
+ forwardText(line_copy.str().data(), line_copy.str().size());
}
}
diff --git a/logd/src/logd/watcher.cpp b/logd/src/logd/watcher.cpp
index a92ad456e9f..fca9cd648bb 100644
--- a/logd/src/logd/watcher.cpp
+++ b/logd/src/logd/watcher.cpp
@@ -222,7 +222,7 @@ Watcher::watchfile()
}
while (nnl != nullptr && elapsed(tickStart) < 1) {
++nnl;
- _forwarder.forwardLine(std::string_view(l, (nnl - l)));
+ _forwarder.forwardLine(std::string_view(l, (nnl - l) - 1));
ssize_t wsize = nnl - l;
offset += wsize;
l = nnl;
diff --git a/logd/src/tests/legacy_forwarder/legacy_forwarder_test.cpp b/logd/src/tests/legacy_forwarder/legacy_forwarder_test.cpp
index d3339894819..67d47a49384 100644
--- a/logd/src/tests/legacy_forwarder/legacy_forwarder_test.cpp
+++ b/logd/src/tests/legacy_forwarder/legacy_forwarder_test.cpp
@@ -40,7 +40,7 @@ struct ForwardFixture {
timer.SetNow();
std::stringstream ss;
ss << std::fixed << timer.Secs();
- ss << "\texample.yahoo.com\t7518/34779\tlogd\tlogdemon\tevent\tstarted/1 name=\"logdemon\"\n";
+ ss << "\texample.yahoo.com\t7518/34779\tlogd\tlogdemon\tevent\tstarted/1 name=\"logdemon\"";
return ss.str();
}
@@ -50,7 +50,7 @@ struct ForwardFixture {
int rfd = open(fname.c_str(), O_RDONLY);
char *buffer[2048];
ssize_t bytes = read(rfd, buffer, 2048);
- ssize_t expected = doForward ? logLine.length() : 0;
+ ssize_t expected = doForward ? logLine.length() + 1 : 0;
EXPECT_EQUAL(expected, bytes);
close(rfd);
}
diff --git a/logd/src/tests/watcher/watcher_test.cpp b/logd/src/tests/watcher/watcher_test.cpp
index c2b379cc1a4..fffaac17058 100644
--- a/logd/src/tests/watcher/watcher_test.cpp
+++ b/logd/src/tests/watcher/watcher_test.cpp
@@ -71,8 +71,7 @@ struct DummyForwarder : public Forwarder {
void sendMode() override { ++sendModeCount; }
void forwardLine(std::string_view log_line) override {
std::lock_guard guard(lock);
- assert(log_line.size() > 0u);
- lines.emplace_back(log_line.substr(0, log_line.size() - 1));
+ lines.emplace_back(log_line);
cond.notify_all();
}
void flush() override { }
diff --git a/vespalog/src/vespa/log/log_message.cpp b/vespalog/src/vespa/log/log_message.cpp
index 77f9b619e9f..8ce7df93a12 100644
--- a/vespalog/src/vespa/log/log_message.cpp
+++ b/vespalog/src/vespa/log/log_message.cpp
@@ -31,18 +31,29 @@ find_tab(std::string_view log_line, const char *tab_name, std::string_view::size
}
int64_t
-parse_time_field(std::string time_field)
+parse_time_subfield(std::string time_subfield, const std::string &time_field)
{
- std::istringstream time_stream(time_field);
- time_stream.imbue(clocale);
- double logtime = 0;
- time_stream >> logtime;
- if (!time_stream.eof()) {
+ std::istringstream subfield_stream(time_subfield);
+ subfield_stream.imbue(clocale);
+ int64_t result = 0;
+ subfield_stream >> result;
+ if (!subfield_stream.eof()) {
std::ostringstream os;
os << "Bad time field: " << time_field;
throw BadLogLineException(os.str());
}
- return logtime * 1000000000;
+ return result;
+}
+
+int64_t
+parse_time_field(std::string time_field)
+{
+ auto dotPos = time_field.find('.');
+ int64_t log_time = parse_time_subfield(time_field.substr(0, dotPos), time_field) * 1000000000;
+ if (dotPos != std::string::npos) {
+ log_time += parse_time_subfield((time_field.substr(dotPos + 1) + "000000000").substr(0, 9), time_field);
+ }
+ return log_time;
}
struct PidFieldParser