loolwsd/LoadTest.cpp | 20 ++++++----------- loolwsd/Util.cpp | 60 +++++++++++++++++++++++++-------------------------- loolwsd/Util.hpp | 2 - 3 files changed, 38 insertions(+), 44 deletions(-)
New commits: commit 1e24456121bd060948fdf0bc6b93be8ea881d6d2 Author: Ashod Nakashian <[email protected]> Date: Sun Dec 27 15:15:57 2015 -0500 loolwsd: logPrefix cleanup Change-Id: I41465a06b17876c5d5fb7a6f9d8569d80571fcca Reviewed-on: https://gerrit.libreoffice.org/20977 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/LoadTest.cpp b/loolwsd/LoadTest.cpp index 9ef5263..06bbaf3 100644 --- a/loolwsd/LoadTest.cpp +++ b/loolwsd/LoadTest.cpp @@ -96,10 +96,8 @@ public: if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE) { #if 0 - std::cout << - Util::logPrefix() << - "Client got " << n << " bytes: " << getAbbreviatedMessage(buffer, n) << - std::endl; + Log::debug() << "Client got " << n << " bytes: " + << getAbbreviatedMessage(buffer, n) << Log::end; #endif std::string response = getFirstLine(buffer, n); StringTokenizer tokens(response, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); @@ -112,10 +110,8 @@ public: n = _ws.receiveFrame(largeBuffer, size, flags); #if 0 - std::cout << - Util::logPrefix() << - "Client got " << n << " bytes: " << getAbbreviatedMessage(largeBuffer, n) << - std::endl; + Log::debug() << "Client got " << n << " bytes: " + << getAbbreviatedMessage(largeBuffer, n) << Log::end; #endif response = getFirstLine(buffer, n); } @@ -137,7 +133,7 @@ public: Application::instance().logger().error("WebSocketException: " + exc.message()); _ws.close(); } - std::cout << Util::logPrefix() << "Got " << tileCount << " tiles" << std::endl; + Log::debug() << "Got " << tileCount << " tiles" << Log::end; } WebSocket& _ws; @@ -192,7 +188,7 @@ private: URI uri(_app.getURL()); - std::cout << Util::logPrefix() << "Starting client for '" << document << "'" << std::endl; + Log::debug() << "Starting client for '" << document << "'" << Log::end; HTTPClientSession cs(uri.getHost(), uri.getPort()); HTTPRequest request(HTTPRequest::HTTP_GET, "/ws"); @@ -219,7 +215,7 @@ private: cond.wait(mutex); mutex.unlock(); - std::cout << Util::logPrefix() << "Got status, size=" << output._width << "x" << output._height << std::endl; + Log::debug() << "Got status, size=" << output._width << "x" << output._height << Log::end; int y = 0; const int DOCTILESIZE = 5000; @@ -253,7 +249,7 @@ private: Thread::sleep(10000); - std::cout << Util::logPrefix() << "Sent " << requestCount << " tile requests, shutting down client for '" << document << "'" << std::endl; + Log::debug() << "Sent " << requestCount << " tile requests, shutting down client for '" << document << "'" << Log::end; ws.shutdown(); thread.join(); diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index b3aac5f..1746767 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -73,9 +73,33 @@ namespace rng namespace Log { + static const Poco::Int64 epochStart = Poco::Timestamp().epochMicroseconds(); static std::string SourceName; static std::string SourceId; + std::string logPrefix() + { + Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - epochStart; + + const Poco::Int64 one_s = 1000000; + const Poco::Int64 hours = usec / (one_s*60*60); + usec %= (one_s*60*60); + const Poco::Int64 minutes = usec / (one_s*60); + usec %= (one_s*60); + const Poco::Int64 seconds = usec / (one_s); + usec %= (one_s); + + std::ostringstream stream; + stream << Log::SourceId << '-' << std::setw(2) << std::setfill('0') + << (Poco::Thread::current() ? Poco::Thread::current()->id() : 0) << ',' + << std::setw(2) << hours << ':' << std::setw(2) << minutes << ':' + << std::setw(2) << seconds << "." << std::setw(6) << usec + << ", "; + + return stream.str(); + } + + void initialize(const std::string& name) { SourceName = name; @@ -110,56 +134,32 @@ namespace Log void trace(const std::string& msg) { - logger().trace(Util::logPrefix() + msg); + logger().trace(logPrefix() + msg); } void debug(const std::string& msg) { - logger().debug(Util::logPrefix() + msg); + logger().debug(logPrefix() + msg); } void info(const std::string& msg) { - logger().information(Util::logPrefix() + msg); + logger().information(logPrefix() + msg); } void warn(const std::string& msg) { - logger().warning(Util::logPrefix() + msg); + logger().warning(logPrefix() + msg); } void error(const std::string& msg) { - logger().error(Util::logPrefix() + msg + " (" + strerror(errno) + ")."); + logger().error(logPrefix() + msg + " (" + strerror(errno) + ")."); } } namespace Util { - static const Poco::Int64 epochStart = Poco::Timestamp().epochMicroseconds(); - - std::string logPrefix() - { - Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - epochStart; - - const Poco::Int64 one_s = 1000000; - const Poco::Int64 hours = usec / (one_s*60*60); - usec %= (one_s*60*60); - const Poco::Int64 minutes = usec / (one_s*60); - usec %= (one_s*60); - const Poco::Int64 seconds = usec / (one_s); - usec %= (one_s); - - std::ostringstream stream; - stream << Log::SourceId << '-' << std::setw(2) << std::setfill('0') - << (Poco::Thread::current() ? Poco::Thread::current()->id() : 0) << ',' - << std::setw(2) << hours << ':' << std::setw(2) << minutes << ':' - << std::setw(2) << seconds << "." << std::setw(6) << usec - << ", "; - - return stream.str(); - } - bool windowingAvailable() { #ifdef __linux @@ -217,7 +217,7 @@ namespace Util } catch (const Poco::IOException& exc) { - Poco::Util::Application::instance().logger().error(logPrefix() + "IOException: " + exc.message()); + Log::error("IOException: " + exc.message()); } } diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index 7f7f213..d4a8640 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -28,8 +28,6 @@ namespace Util unsigned getNext(); } - std::string logPrefix(); - bool windowingAvailable(); // Sadly, older libpng headers don't use const for the pixmap pointer parameter to _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
