[Libreoffice-commits] online.git: loolwsd/IoUtil.cpp loolwsd/Util.cpp loolwsd/Util.hpp
Tor Lillqvist
tml at collabora.com
Thu Mar 31 08:04:35 UTC 2016
loolwsd/IoUtil.cpp | 6 +++---
loolwsd/Util.cpp | 22 ++++++++++++++++++++++
loolwsd/Util.hpp | 4 ++++
3 files changed, 29 insertions(+), 3 deletions(-)
New commits:
commit 422834ebefcf0d69aa0ff997ce61bb927407e763
Author: Tor Lillqvist <tml at collabora.com>
Date: Thu Mar 31 11:01:21 2016 +0300
Improve logging
Don't embed newlines in "lines" written to the log. When logging stuff
read from or written to the fifos, translate newlines to " / " for
clarity.
(If we would want complete, exact verbose logging, we should be really
pedantic and log all non-printable bytes in hex anyway, etc, so
displaying newlines as space-separated slashes should be OK. It isn't
as if there would be totally arbitary data passed through the fifos
anyway.)
diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index 02ecb09..f47f454 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -210,7 +210,7 @@ ssize_t writeFIFO(int pipe, const char* buffer, ssize_t size)
ssize_t count = 0;
while(true)
{
- Log::trace("Writing to pipe. Data: [" + std::string(buffer, size) + "].");
+ Log::trace("Writing to pipe. Data: [" + Util::formatLinesForLog(std::string(buffer, size)) + "].");
const auto bytes = write(pipe, buffer + count, size - count);
if (bytes < 0)
{
@@ -282,7 +282,7 @@ int PipeReader::readLine(std::string& line,
line += std::string(_data.data(), endOfLine);
_data.erase(0, endOfLine - _data.data() + 1); // Including the '\n'.
Log::trace() << "Read existing line from pipe: " << _name << ", line: ["
- << line << "], data: [" << _data << "]." << Log::end;
+ << line << "], data: [" << Util::formatLinesForLog(_data) << "]." << Log::end;
return 1;
}
@@ -332,7 +332,7 @@ int PipeReader::readLine(std::string& line,
line += tail;
_data = std::string(endOfLine + 1, bytes - tail.size() - 1); // Exclude the '\n'.
Log::trace() << "Read line from pipe: " << _name << ", line: [" << line
- << "], data: [" << _data << "]." << Log::end;
+ << "], data: [" << Util::formatLinesForLog(_data) << "]." << Log::end;
return 1;
}
else
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 44cee5c..5d6485d 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -511,6 +511,28 @@ namespace Util
return nMem;
}
+
+ std::string replace(const std::string& s, const std::string& a, const std::string& b)
+ {
+ std::string result = s;
+ std::string::size_type pos;
+ while ((pos = result.find(a)) != std::string::npos)
+ {
+ result = result.replace(pos, a.size(), b);
+ }
+ return result;
+ }
+
+ std::string formatLinesForLog(const std::string& s)
+ {
+ std::string r;
+ std::string::size_type n = s.size();
+ if (n > 0 && s.back() == '\n')
+ r = s.substr(0, n-1);
+ else
+ r = s;
+ return replace(r, "\n", " / ");
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index ae3f938..d02fa10 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -127,6 +127,10 @@ namespace Util
void requestTermination(const Poco::Process::PID& pid);
unsigned getMemoryUsage(Poco::Process::PID nPid);
+
+ std::string replace(const std::string& s, const std::string& a, const std::string& b);
+
+ std::string formatLinesForLog(const std::string& s);
};
//TODO: Move to own file.
More information about the Libreoffice-commits
mailing list