aboutsummaryrefslogtreecommitdiffstats
path: root/logd
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2019-04-03 14:37:01 +0200
committerTor Egge <Tor.Egge@broadpark.no>2019-04-03 14:37:01 +0200
commitdac529d0484c34424d3930e1b2ac4737ae98812f (patch)
tree410c3240b43baa5b91fdbe57f49ebcf820a64ec2 /logd
parent162d34589e06059c2cbfdfb6b23da7c0bab0f2f6 (diff)
Change Watcher to not pass newline to forwardLine().
Diffstat (limited to 'logd')
-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
4 files changed, 8 insertions, 8 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 { }