[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp | 14 -- 1 file changed, 4 insertions(+), 10 deletions(-) New commits: commit 4d5bf74c9f6979f1498b3daa20e213e7dda27fc5 Author: Tor Lillqvist AuthorDate: Fri Jul 10 11:33:14 2020 +0300 Commit: Tor Lillqvist CommitDate: Fri Jul 10 10:56:57 2020 +0200 Don't bother outputting the thread id in hex for iOS to log We output the informative name we give ourselves to the thread anyway which is much more useful. Change-Id: I74721cc0014fa657adfb6ecea05bcd7f846421a4 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98477 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice Reviewed-by: Tor Lillqvist diff --git a/common/Log.cpp b/common/Log.cpp index 0ae19df66..bc3637183 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -189,14 +189,15 @@ namespace Log // Don't bother with the "Source" which would be just "Mobile" always and non-informative as // there is just one process in the app anyway. char *pos = buffer; + +// Don't bother with the thread identifier either. We output the thread name which is much +// more useful anyway. #else // Note that snprintf is deemed signal-safe in most common implementations. char* pos = strcopy((Source.getInited() ? Source.getId().c_str() : ""), buffer); *pos++ = '-'; -#endif // Thread ID. -#ifdef __linux const long osTid = Util::getThreadId(); if (osTid > 9) { @@ -213,17 +214,10 @@ namespace Log to_ascii_fixed<5>(pos, osTid); pos += 5; } -#elif defined IOS -uint64_t osTid; -pthread_threadid_np(nullptr, &osTid); -snprintf(pos, 32, "%#.05llx", osTid); -// Skip to end. -while (*pos) -pos++; +*pos++ = ' '; #endif // -MM-DD. -*pos++ = ' '; to_ascii_fixed<4>(pos, time.year()); pos[4] = '-'; pos += 5; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |6 ++ 1 file changed, 6 insertions(+) New commits: commit f1b13c7e777976976caad6ab864e18fc95db0a59 Author: Tor Lillqvist AuthorDate: Thu Jul 2 22:15:08 2020 +0300 Commit: Tor Lillqvist CommitDate: Thu Jul 2 22:16:53 2020 +0300 Drop the fixed prefix ("Mobile-") from log output in the iOS app There is just one process in the app so logging its name which always is the same is pointless. Change-Id: I89dbabc26457a142d35bf748981edb670cba4732 diff --git a/common/Log.cpp b/common/Log.cpp index e001980af..0ae19df66 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -185,9 +185,15 @@ namespace Log char* prefix(const Poco::DateTime& time, char* buffer, const char* level) { +#ifdef IOS +// Don't bother with the "Source" which would be just "Mobile" always and non-informative as +// there is just one process in the app anyway. +char *pos = buffer; +#else // Note that snprintf is deemed signal-safe in most common implementations. char* pos = strcopy((Source.getInited() ? Source.getId().c_str() : ""), buffer); *pos++ = '-'; +#endif // Thread ID. #ifdef __linux ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) New commits: commit 21f0e52ce350c2724f0e928fff26532756049339 Author: Tor Lillqvist AuthorDate: Thu Jul 2 22:00:34 2020 +0300 Commit: Tor Lillqvist CommitDate: Thu Jul 2 22:08:39 2020 +0300 Fix iOS logging breakage after 287b70a50408d260f3c6c0d5306c081a40eea280 This: while (*pos++); leaves pos pointing to the char *after* the first null char. Thus we lost the timestamp, thread name, and message log level. The log output ended up loooking like: Mobile-0x42a805To JS: loolserver { "Version": "master..", "Hash": "1e3b28b0", "Protocol": "0.1", "Id": "e42d1a33" }| CODocument.mm:115 with no space between the thread id and the message, while what we expect is: Mobile-0x42be9e 2020-07-02 18:59:30.490298 [ main ] INF To JS: loolserver { "Version": "master..", "Hash": "1e3b28b0", "Protocol": "0.1", "Id": "46ebf726" }| CODocument.mm:115 As such it is not necessary to show "Mobile" (the name of the process's main program) in the log messages. There is just one process. Will remove that in a later commit. Change-Id: I55c4a82f2b34e3b9e70e86cc7af8ea42a3108695 diff --git a/common/Log.cpp b/common/Log.cpp index feabf0216..e001980af 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -211,7 +211,9 @@ namespace Log uint64_t osTid; pthread_threadid_np(nullptr, &osTid); snprintf(pos, 32, "%#.05llx", osTid); -while (*pos++); // Skip to end. +// Skip to end. +while (*pos) +pos++; #endif // -MM-DD. ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp | 155 + common/Log.hpp | 20 --- 2 files changed, 148 insertions(+), 27 deletions(-) New commits: commit 287b70a50408d260f3c6c0d5306c081a40eea280 Author: Ashod Nakashian AuthorDate: Sat Apr 25 13:03:32 2020 -0400 Commit: Ashod Nakashian CommitDate: Fri May 22 00:40:37 2020 +0200 wsd: logging cleanup and improvements We now don't need to call snprintf (which is best for signal-safetly), and are much faster thanks to a custom replacement. Change-Id: Iae5861e42e8e335967499f93b71b39b0b4b09bf6 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/94146 Tested-by: Jenkins CollaboraOffice Tested-by: Jenkins Reviewed-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index f9d0b5578..6cb376c9e 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -70,7 +70,7 @@ namespace Log const std::string& getName() const { return _name; } void setLogger(Poco::Logger* logger) { _logger = logger; }; -Poco::Logger* getLogger() { return _logger; } +Poco::Logger* getLogger() const { return _logger; } }; static StaticNameHelper Source; bool IsShutdown = false; @@ -112,38 +112,153 @@ namespace Log signalLog(buf + i + 1); } -char* prefix(char* buffer, const std::size_t len, const char* level) +/// Convert an unsigned number to ascii with 0 padding. +template void to_ascii_fixed(char* buf, size_t num) { -const char *threadName = Util::getThreadName(); -Poco::DateTime time; +buf[Width - 1] = '0' + num % 10; // Units. + +if (Width > 1) +{ +num /= 10; +buf[Width - 2] = '0' + num % 10; // Tens. +} + +if (Width > 2) +{ +num /= 10; +buf[Width - 3] = '0' + num % 10; // Hundreds. +} + +if (Width > 3) +{ +num /= 10; +buf[Width - 4] = '0' + num % 10; // Thousands. +} + +if (Width > 4) +{ +num /= 10; +buf[Width - 5] = '0' + num % 10; // Ten-Thousands. +} + +if (Width > 5) +{ +num /= 10; +buf[Width - 6] = '0' + num % 10; // Hundred-Thousands. +} + +static_assert(Width >= 1 && Width <= 6, "Width is invalid."); +} + +/// Copy a null-terminated string into another. +/// Expects the destination to be large enough. +/// Note: unlike strcpy, this returns the *new* out +/// (destination) pointer, which saves a strlen call. +char* strcopy(const char* in, char* out) +{ +while (*in) +*out++ = *in++; +return out; +} + +/// Convert unsigned long num to base-10 ascii in place. +/// Returns the *end* position. +char* to_ascii(char* buf, size_t num) +{ +int i = 0; +do +{ +buf[i++] = '0' + num % 10; +num /= 10; +} while (num > 0); + +// Reverse. +for (char *front = buf, *back = buf + i - 1; back > front; ++front, --back) +{ +const char t = *front; +*front = *back; +*back = t; +} + +return buf + i; +} + +char* prefix(const Poco::DateTime& time, char* buffer, const char* level) +{ +// Note that snprintf is deemed signal-safe in most common implementations. +char* pos = strcopy((Source.getInited() ? Source.getId().c_str() : ""), buffer); +*pos++ = '-'; + +// Thread ID. #ifdef __linux const long osTid = Util::getThreadId(); -// Note that snprintf is deemed signal-safe in most common implementations. -snprintf(buffer, len, "%s-%.05lu %.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.6u [ %s ] %s ", -(Source.getInited() ? Source.getId().c_str() : ""), -osTid, -time.year(), time.month(), time.day(), -time.hour(), time.minute(), time.second(), -time.millisecond() * 1000 + time.microsecond(), -threadName, level); +if (osTid > 9) +{ +if (osTid > 99) +pos = to_ascii(pos, osTid); +else +{ +to_ascii_fixed<6>(pos, osTid); +pos += 6; +} +} +else +{ +to_ascii_fixed<5>(pos, osTid); +pos += 5; +} #elif defined IOS uint64_t osTid; pthread_threadid_np(nullptr, &osTid); -snprintf(buffer, len, "%s-%#.05llx %.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.6u [ %s ] %s ", -(Source.getInited() ? Source.getId().c_str() : ""), -osTid, -time.year(), time.month(), time.day(), -time.hour(), time.minute(), time.second(), -time.m
[Libreoffice-commits] online.git: common/Log.cpp common/Session.hpp common/Util.cpp common/Util.hpp kit/ChildSession.cpp kit/ForKit.cpp kit/Kit.cpp net/Ssl.cpp tools/Config.cpp tools/KitClient.cpp wsd
common/Log.cpp |1 - common/Session.hpp |1 - common/Util.cpp|9 - common/Util.hpp| 10 +- kit/ChildSession.cpp |3 +-- kit/ForKit.cpp | 15 ++- kit/Kit.cpp|1 - net/Ssl.cpp|2 +- tools/Config.cpp |1 + tools/KitClient.cpp|1 - wsd/Admin.cpp |4 ++-- wsd/Admin.hpp |4 ++-- wsd/AdminModel.cpp |5 ++--- wsd/AdminModel.hpp | 12 +--- wsd/DocumentBroker.hpp |4 ++-- wsd/LOOLWSD.cpp|3 +-- wsd/LOOLWSD.hpp|7 +++ 17 files changed, 35 insertions(+), 48 deletions(-) New commits: commit 8b349716eb58c1024f21627f78f8e66657e24bf2 Author: Pranam Lashkari AuthorDate: Tue Nov 26 18:45:38 2019 +0530 Commit: Jan Holesovsky CommitDate: Wed Apr 29 14:27:54 2020 +0200 killpoco: removed Poco::Process completely Change-Id: Iba67abf9342c11517c69c1d94903bf4752aa87d6 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/83770 Tested-by: Jenkins CollaboraOffice Reviewed-by: Jan Holesovsky diff --git a/common/Log.cpp b/common/Log.cpp index d96bd3f82..f9d0b5578 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include diff --git a/common/Session.hpp b/common/Session.hpp index 402223963..02a11fa23 100644 --- a/common/Session.hpp +++ b/common/Session.hpp @@ -19,7 +19,6 @@ #include #include -#include #include #include "Protocol.hpp" diff --git a/common/Util.cpp b/common/Util.cpp index e4d19adb1..0ae624983 100644 --- a/common/Util.cpp +++ b/common/Util.cpp @@ -52,7 +52,6 @@ #include #include #include -#include #include #include #include @@ -448,7 +447,7 @@ namespace Util return oss.str(); } -size_t getMemoryUsagePSS(const Poco::Process::PID pid) +size_t getMemoryUsagePSS(const pid_t pid) { if (pid > 0) { @@ -465,7 +464,7 @@ namespace Util return 0; } -size_t getMemoryUsageRSS(const Poco::Process::PID pid) +size_t getMemoryUsageRSS(const pid_t pid) { static const int pageSizeBytes = getpagesize(); size_t rss = 0; @@ -480,7 +479,7 @@ namespace Util return 0; } -size_t getCpuUsage(const Poco::Process::PID pid) +size_t getCpuUsage(const pid_t pid) { if (pid > 0) { @@ -492,7 +491,7 @@ namespace Util return 0; } -size_t getStatFromPid(const Poco::Process::PID pid, int ind) +size_t getStatFromPid(const pid_t pid, int ind) { if (pid > 0) { diff --git a/common/Util.hpp b/common/Util.hpp index d154942f8..105eef7dd 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -31,7 +32,6 @@ #include #include -#include #include #define LOK_USE_UNSTABLE_API @@ -135,10 +135,10 @@ namespace Util size_t getTotalSystemMemoryKb(); /// Returns the process PSS in KB (works only when we have perms for /proc/pid/smaps). -size_t getMemoryUsagePSS(const Poco::Process::PID pid); +size_t getMemoryUsagePSS(const pid_t pid); /// Returns the process RSS in KB. -size_t getMemoryUsageRSS(const Poco::Process::PID pid); +size_t getMemoryUsageRSS(const pid_t pid); /// Returns the RSS and PSS of the current process in KB. /// Example: "procmemstats: pid=123 rss=12400 pss=566" @@ -148,9 +148,9 @@ namespace Util /// returns them as a pair in the same order std::pair getPssAndDirtyFromSMaps(FILE* file); -size_t getCpuUsage(const Poco::Process::PID pid); +size_t getCpuUsage(const pid_t pid); -size_t getStatFromPid(const Poco::Process::PID pid, int ind); +size_t getStatFromPid(const pid_t pid, int ind); #endif std::string replace(std::string s, const std::string& a, const std::string& b); diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index aa9f2545c..f576f2785 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #if !MOBILEAPP #include #include @@ -616,7 +615,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, const S #if defined(ENABLE_DEBUG) && !MOBILEAPP if (std::getenv("PAUSEFORDEBUGGER")) { -std::cerr << getDocURL() << " paused waiting for a debugger to attach: " << Poco::Process::id() << std::endl; +std::cerr << getDocURL() << " paused waiting for a debugger to attach: " << getpid() << std::endl; SigUtil::setDebuggerSignal(); pause(); } diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp index b15a4bea2..c820305ff 100644 --- a/kit/ForKit.cpp +++ b/kit/ForKit.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include "Kit.hpp" @@ -45,8 +44,6 @@ #include #include -using Poco::Proc
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp | 12 common/Log.hpp |7 +-- 2 files changed, 9 insertions(+), 10 deletions(-) New commits: commit 1339b36575b28468ab5ef293a381c5f91eb15b76 Author: Ashod Nakashian AuthorDate: Thu Mar 12 11:06:40 2020 -0400 Commit: Ashod Nakashian CommitDate: Sat Mar 14 14:23:27 2020 +0100 wsd: define Log::shutdown for Mobile to avoid special casing at call sites Change-Id: I9125df562c96b3671cb47200a36aae145cf29259 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90423 Tested-by: Jenkins CollaboraOffice Reviewed-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index ef2b03038..d96bd3f82 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -218,24 +218,20 @@ namespace Log : Poco::Logger::get(Source.getInited() ? Source.getName() : std::string()); } -#if !MOBILEAPP void shutdown() { -Poco::Logger::shutdown(); +#if !MOBILEAPP IsShutdown = true; +Poco::Logger::shutdown(); + // Flush std::flush(std::cout); fflush(stdout); std::flush(std::cerr); fflush(stderr); -} - -bool isShutdownCalled() -{ -return IsShutdown; -} #endif +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/common/Log.hpp b/common/Log.hpp index 35aaa0834..aa83bc171 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -56,11 +56,14 @@ namespace Log /// Returns the underlying logging system. Poco::Logger& logger(); -#if !MOBILEAPP /// Shutdown and release the logging system. void shutdown(); + +#if !MOBILEAPP +extern bool IsShutdown; + /// Was static shutdown() called? If so, producing more logs should be avoided. -bool isShutdownCalled(); +inline bool isShutdownCalled() { return IsShutdown; } #else constexpr bool isShutdownCalled() { return false; } #endif ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/SigUtil.cpp
common/Log.cpp |3 ++- common/SigUtil.cpp | 41 + 2 files changed, 11 insertions(+), 33 deletions(-) New commits: commit 3ebbc6213b6e398bfc4a71b3eb5f03f421d0ffe6 Author: Ashod Nakashian AuthorDate: Mon Nov 18 22:13:00 2019 -0500 Commit: Ashod Nakashian CommitDate: Tue Nov 19 16:13:33 2019 +0100 wsd: avoid malloc in signal handler malloc is not signal safe, and must not be called from signal-safe functions. If malloc itself signals, calling it in the signal handler can deadlock. Luckily, we only needed malloc for getting the backtrace strings. Now we just write directly to stderr, which is faster, cleaner, and safer. Change-Id: I54093f45e05f2a0fd3c5cde0cc2104ffe6d81d2a Reviewed-on: https://gerrit.libreoffice.org/83151 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index e08287bb9..ef2b03038 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -83,7 +83,7 @@ namespace Log while (true) { const int length = std::strlen(message); -const int written = write (STDERR_FILENO, message, length); +const int written = write(STDERR_FILENO, message, length); if (written < 0) { if (errno == EINTR) @@ -119,6 +119,7 @@ namespace Log Poco::DateTime time; #ifdef __linux const long osTid = Util::getThreadId(); +// Note that snprintf is deemed signal-safe in most common implementations. snprintf(buffer, len, "%s-%.05lu %.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.6u [ %s ] %s ", (Source.getInited() ? Source.getId().c_str() : ""), osTid, diff --git a/common/SigUtil.cpp b/common/SigUtil.cpp index e5dabcb6f..c24ffb9d5 100644 --- a/common/SigUtil.cpp +++ b/common/SigUtil.cpp @@ -251,13 +251,6 @@ namespace SigUtil Log::signalLog(signalName(signal)); Log::signalLog("\n"); -if (std::getenv("LOOL_DEBUG")) -{ -Log::signalLog(FatalGdbString); -LOG_ERR("Sleeping 30s to allow debugging."); -sleep(30); -} - struct sigaction action; sigemptyset(&action.sa_mask); @@ -274,34 +267,17 @@ namespace SigUtil void dumpBacktrace() { -char header[32]; -sprintf(header, "Backtrace %d:\n", getpid()); - #if !defined(__ANDROID__) +Log::signalLog("\nBacktrace "); +Log::signalLogNumber(getpid()); +Log::signalLog(":\n"); + const int maxSlots = 50; void *backtraceBuffer[maxSlots]; -int numSlots = backtrace(backtraceBuffer, maxSlots); +const int numSlots = backtrace(backtraceBuffer, maxSlots); if (numSlots > 0) { -char **symbols = backtrace_symbols(backtraceBuffer, numSlots); -if (symbols != nullptr) -{ -struct iovec ioVector[maxSlots*2+1]; -ioVector[0].iov_base = static_cast(header); -ioVector[0].iov_len = std::strlen(static_cast(ioVector[0].iov_base)); -for (int i = 0; i < numSlots; i++) -{ -ioVector[1+i*2+0].iov_base = symbols[i]; -ioVector[1+i*2+0].iov_len = std::strlen(static_cast(ioVector[1+i*2+0].iov_base)); -ioVector[1+i*2+1].iov_base = const_cast(static_cast("\n")); -ioVector[1+i*2+1].iov_len = 1; -} - -if (writev(STDERR_FILENO, ioVector, numSlots*2+1) == -1) -{ -LOG_SYS("Failed to dump backtrace to stderr."); -} -} +backtrace_symbols_fd(backtraceBuffer, numSlots, STDERR_FILENO); } #else LOG_SYS("Backtrace not available on Android."); @@ -309,6 +285,7 @@ namespace SigUtil if (std::getenv("LOOL_DEBUG")) { +Log::signalLog(FatalGdbString); LOG_ERR("Sleeping 30s to allow debugging."); sleep(30); } @@ -328,9 +305,9 @@ namespace SigUtil sigaction(SIGILL, &action, nullptr); sigaction(SIGFPE, &action, nullptr); -// prepare this in advance just in case. +// Prepare this in advance just in case. std::ostringstream stream; -stream << "\nFatal signal! Attach debugger with:\n" +stream << "\nERROR: Fatal signal! Attach debugger with:\n" << "sudo gdb --pid=" << getpid() << "\n or \n" << "sudo gdb --q --n --ex 'thread apply all backtrace full' --batch --pid=" << getpid() << "\n"; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/SigUtil.cpp common/Util.cpp
common/Log.cpp |2 +- common/SigUtil.cpp |6 +++--- common/Util.cpp|2 +- 3 files changed, 5 insertions(+), 5 deletions(-) New commits: commit 189cd0e3891f9aeb93bc4314209032c89a746eff Author: Jan Holesovsky AuthorDate: Thu Nov 7 11:53:37 2019 +0100 Commit: Jan Holesovsky CommitDate: Thu Nov 7 12:24:53 2019 +0100 killpoco: Get rid of Poco::Process:id() usage. Change-Id: If060767389f9fa57deba1ceefc872bac03763498 Reviewed-on: https://gerrit.libreoffice.org/82208 Reviewed-by: Jan Holesovsky Tested-by: Jan Holesovsky diff --git a/common/Log.cpp b/common/Log.cpp index bb9ba9d39..e08287bb9 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -158,7 +158,7 @@ namespace Log oss << Source.getName(); #if !MOBILEAPP // Just one process in a mobile app, the pid is uninteresting. oss << '-' -<< std::setw(5) << std::setfill('0') << Poco::Process::id(); +<< std::setw(5) << std::setfill('0') << getpid(); #endif Source.setId(oss.str()); diff --git a/common/SigUtil.cpp b/common/SigUtil.cpp index 212d1382f..4003d8d73 100644 --- a/common/SigUtil.cpp +++ b/common/SigUtil.cpp @@ -236,7 +236,7 @@ namespace SigUtil dumpBacktrace(); // let default handler process the signal -kill(Poco::Process::id(), signal); +kill(getpid(), signal); } void dumpBacktrace() @@ -298,9 +298,9 @@ namespace SigUtil // prepare this in advance just in case. std::ostringstream stream; stream << "\nFatal signal! Attach debugger with:\n" - << "sudo gdb --pid=" << Poco::Process::id() << "\n or \n" + << "sudo gdb --pid=" << getpid() << "\n or \n" << "sudo gdb --q --n --ex 'thread apply all backtrace full' --batch --pid=" - << Poco::Process::id() << "\n"; + << getpid() << "\n"; std::string streamStr = stream.str(); assert (sizeof (FatalGdbString) > strlen(streamStr.c_str()) + 1); strncpy(FatalGdbString, streamStr.c_str(), sizeof(FatalGdbString)-1); diff --git a/common/Util.cpp b/common/Util.cpp index b493afeca..a589785d4 100644 --- a/common/Util.cpp +++ b/common/Util.cpp @@ -608,7 +608,7 @@ namespace Util std::string UniqueId() { static std::atomic_int counter(0); -return std::to_string(Poco::Process::id()) + '/' + std::to_string(counter++); +return std::to_string(getpid()) + '/' + std::to_string(counter++); } std::map JsonToMap(const std::string& jsonString) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Util.cpp kit/ChildSession.hpp kit/Kit.cpp wsd/LOOLWSD.cpp
common/Log.cpp |2 +- common/Util.cpp |1 - kit/ChildSession.hpp |1 - kit/Kit.cpp |3 --- wsd/LOOLWSD.cpp |8 ++-- 5 files changed, 3 insertions(+), 12 deletions(-) New commits: commit 5d0d3a4869332aea592ef468f653150c7d594cee Author: Jan Holesovsky AuthorDate: Thu Nov 7 11:42:24 2019 +0100 Commit: Jan Holesovsky CommitDate: Thu Nov 7 12:24:26 2019 +0100 killpoco: Get rid of Poco/Thread.h from the rest of the Android-related files. Change-Id: I724230a4428cab3cc26245ac4aa43a91af2e09ce Reviewed-on: https://gerrit.libreoffice.org/82204 Reviewed-by: Jan Holesovsky Tested-by: Jan Holesovsky diff --git a/common/Log.cpp b/common/Log.cpp index cdb72a903..bb9ba9d39 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #include "Log.hpp" diff --git a/common/Util.cpp b/common/Util.cpp index 49d465035..b493afeca 100644 --- a/common/Util.cpp +++ b/common/Util.cpp @@ -55,7 +55,6 @@ #include #include #include -#include #include #include diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp index 7a5b16df8..88e445671 100644 --- a/kit/ChildSession.hpp +++ b/kit/ChildSession.hpp @@ -18,7 +18,6 @@ #include #include -#include #include "Common.hpp" #include "Kit.hpp" diff --git a/kit/Kit.cpp b/kit/Kit.cpp index cd397d397..4a152ef91 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -51,7 +51,6 @@ #include #include #include -#include #include #include "ChildSession.hpp" @@ -97,7 +96,6 @@ using Poco::JSON::Array; using Poco::JSON::Object; using Poco::JSON::Parser; using Poco::StringTokenizer; -using Poco::Thread; using Poco::URI; #ifndef BUILDING_TESTS @@ -2057,7 +2055,6 @@ private: /// For showing disconnected user info in the doc repair dialog. std::map _sessionUserInfo; std::chrono::steady_clock::time_point _lastMemStatsTime; -Poco::Thread _callbackThread; friend std::shared_ptr getLOKDocument(); }; diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index ac42e490a..583455d93 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -164,9 +164,6 @@ using Poco::Path; using Poco::StreamCopier; using Poco::StringTokenizer; using Poco::TemporaryFile; -#if FUZZER -using Poco::Thread; -#endif using Poco::URI; using Poco::Util::Application; using Poco::Util::HelpFormatter; @@ -1572,11 +1569,10 @@ void PrisonerPoll::wakeupHook() #endif LOOLWSD::FuzzFileName)); -std::unique_ptr replayThread(new Thread()); -replayThread->start(*replay); +std::thread replayThread([&replay]{ replay->run(); }); // block until the replay finishes -replayThread->join(); +replayThread.join(); LOG_INF("Setting TerminationFlag"); SigUtil::setTerminationFlag(); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |1 + 1 file changed, 1 insertion(+) New commits: commit 56b49b50004cd3577b99ab7a65f7e8c834cd421f Author: Ashod Nakashian AuthorDate: Tue Oct 22 10:30:48 2019 -0400 Commit: Ashod Nakashian CommitDate: Tue Oct 29 02:36:08 2019 +0100 wsd: warning logging on the console is now magenta for visibility Change-Id: I8756a0c38d529495826131a3d2dcd1ab70d8c289 Reviewed-on: https://gerrit.libreoffice.org/81337 Reviewed-by: Andras Timar Tested-by: Andras Timar (cherry picked from commit 7c325c0fb32951dfc8786df98d72e72c92443088) Reviewed-on: https://gerrit.libreoffice.org/81577 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index 00d047e86..cdb72a903 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -177,6 +177,7 @@ namespace Log { channel = static_cast(new Poco::ColorConsoleChannel()); channel->setProperty("traceColor", "green"); +channel->setProperty("warningColor", "magenta"); } else channel = static_cast(new Poco::ConsoleChannel()); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |3 +++ 1 file changed, 3 insertions(+) New commits: commit 5dc8e815c4b9d5b09a90411df8ed2780c78abd59 Author: Ashod Nakashian AuthorDate: Sun Sep 29 17:00:56 2019 -0400 Commit: Michael Meeks CommitDate: Mon Oct 28 10:45:31 2019 +0100 wsd: logging: color trace differently to improve readability Change-Id: I5127061f4d62122d07bad32d4757569f1a9cc877 Reviewed-on: https://gerrit.libreoffice.org/80321 Tested-by: Jenkins CollaboraOffice Reviewed-by: Jan Holesovsky (cherry picked from commit 48387b00077b9baa72508c05e3fc3228a4569998) Reviewed-on: https://gerrit.libreoffice.org/81559 Reviewed-by: Michael Meeks Tested-by: Michael Meeks diff --git a/common/Log.cpp b/common/Log.cpp index 18a0137f5..00d047e86 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -174,7 +174,10 @@ namespace Log } } else if (withColor) +{ channel = static_cast(new Poco::ColorConsoleChannel()); +channel->setProperty("traceColor", "green"); +} else channel = static_cast(new Poco::ConsoleChannel()); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp |2 +- common/Log.hpp |2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) New commits: commit f89264047c17b362ebab8ff96ad2e01ac63bacec Author: Tor Lillqvist AuthorDate: Mon Sep 16 12:29:22 2019 +0300 Commit: Tor Lillqvist CommitDate: Mon Sep 16 13:32:57 2019 +0200 Fix build failure in the MOBILEAPP case We never exit an app process intentionally, so Log::isShutdownCalled() can always return false. Change-Id: I6b3cce85ccac5e3ffbb7b29ca552cb9e4441df2a Reviewed-on: https://gerrit.libreoffice.org/78979 Reviewed-by: Tor Lillqvist Tested-by: Tor Lillqvist diff --git a/common/Log.cpp b/common/Log.cpp index 0153eff14..18a0137f5 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -225,12 +225,12 @@ namespace Log std::flush(std::cerr); fflush(stderr); } -#endif bool isShutdownCalled() { return IsShutdown; } +#endif } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/common/Log.hpp b/common/Log.hpp index 6bf85129e..df0a06536 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -61,6 +61,8 @@ namespace Log void shutdown(); /// Was static shutdown() called? If so, producing more logs should be avoided. bool isShutdownCalled(); +#else +constexpr bool isShutdownCalled() { return false; } #endif char* prefix(char* buffer, std::size_t len, const char* level); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp |2 +- common/Log.hpp | 22 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) New commits: commit 71a942c24b4c4f803a4cf6a968b67b960adce09c Author: Miklos Vajna AuthorDate: Mon Sep 16 10:55:26 2019 +0200 Commit: Miklos Vajna CommitDate: Mon Sep 16 11:52:15 2019 +0200 Log: rename isShutdown to isShutdownCalled Class members that differ only in case are not great. Change-Id: I2e54bf9b6da7e4e15e03389000a6ff86e98c16a6 diff --git a/common/Log.cpp b/common/Log.cpp index c94b382a2..0153eff14 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -227,7 +227,7 @@ namespace Log } #endif -bool isShutdown() +bool isShutdownCalled() { return IsShutdown; } diff --git a/common/Log.hpp b/common/Log.hpp index 6690c01bc..6bf85129e 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -59,8 +59,8 @@ namespace Log #if !MOBILEAPP /// Shutdown and release the logging system. void shutdown(); -/// Was shutdown() called? -bool isShutdown(); +/// Was static shutdown() called? If so, producing more logs should be avoided. +bool isShutdownCalled(); #endif char* prefix(char* buffer, std::size_t len, const char* level); @@ -291,7 +291,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (!Log::isShutdown() && log_.trace()) \ +if (!Log::isShutdownCalled() && log_.trace()) \ { \ LOG_BODY_(log_, TRACE, "TRC", X, true); \ } \ @@ -301,7 +301,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (!Log::isShutdown() && log_.trace()) \ +if (!Log::isShutdownCalled() && log_.trace()) \ { \ LOG_BODY_(log_, TRACE, "TRC", X, false);\ } \ @@ -311,7 +311,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (!Log::isShutdown() && log_.debug()) \ +if (!Log::isShutdownCalled() && log_.debug()) \ { \ LOG_BODY_(log_, DEBUG, "DBG", X, true); \ } \ @@ -321,7 +321,7 @@ namespace Log do\ { \ auto &log_ = Log::logger(); \ -if (!Log::isShutdown() && log_.information()) \ +if (!Log::isShutdownCalled() && log_.information()) \ { \ LOG_BODY_(log_, INFORMATION, "INF", X, true); \ } \ @@ -331,7 +331,7 @@ namespace Log do\ { \ auto &log_ = Log::logger(); \ -if (!Log::isShutdown() && log_.warning()) \ +if (!Log::isShutdownCalled() && log_.warning()) \ { \ LOG_BODY_(log_, WARNING, "WRN", X, true); \ } \ @@ -341,7 +341,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (!Log::isShutdown() && log_.error()) \ +if (!Log::isShutdownCalled() && log_.error()) \ { \ LOG_BODY_(log_, ERROR, "ERR", X, true); \ } \ @@ -351,7 +351,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (!Log::isShutdown() && log_.error()) \ +if (!Log::isShutdownCalled() && log_.error()) \ {
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit f8140acac79142255af6e09c9846b2900a8399d8 Author: Miklos Vajna AuthorDate: Wed Sep 11 12:23:59 2019 +0200 Commit: Miklos Vajna CommitDate: Wed Sep 11 12:23:59 2019 +0200 Avoid static member access through instance Change-Id: Ifbfdfbb0d5b6020908d041904b61a2ed3b8255c1 diff --git a/common/Log.cpp b/common/Log.cpp index 1abb81d28..c94b382a2 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -216,7 +216,7 @@ namespace Log #if !MOBILEAPP void shutdown() { -logger().shutdown(); +Poco::Logger::shutdown(); IsShutdown = true; // Flush ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp |7 +++ common/Log.hpp | 20 +++- 2 files changed, 18 insertions(+), 9 deletions(-) New commits: commit a7d836dd7c2903e40e5a29da34b581d65b28fd84 Author: Miklos Vajna AuthorDate: Mon Sep 9 15:41:09 2019 +0200 Commit: Miklos Vajna CommitDate: Mon Sep 9 15:41:09 2019 +0200 Fix UB in unit-wopi net/Socket.hpp:405:9: runtime error: member call on address 0x6070007a2210 which does not point to an object of type 'Poco::Logger' 0x6070007a2210: note: object has invalid vptr 05 00 80 0e 7c 01 80 6f 3c 7f 00 00 c8 b8 0f 01 3c 7f 00 00 00 00 00 00 be be be be 38 22 7a 00 ^~~ invalid vptr SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior net/Socket.hpp:405:9 in Which is use-after-free: once Poco::Logger::shutdown() is called, we need to tolerate LOG_DBG() and other similar calls, even if they don't go anywhere. Change-Id: Ic76433743177dd2b604ff34e340309c506d83350 diff --git a/common/Log.cpp b/common/Log.cpp index 4441eb785..1abb81d28 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -74,6 +74,7 @@ namespace Log Poco::Logger* getLogger() { return _logger; } }; static StaticNameHelper Source; +bool IsShutdown = false; // We need a signal safe means of writing messages // $ man 7 signal @@ -216,6 +217,7 @@ namespace Log void shutdown() { logger().shutdown(); +IsShutdown = true; // Flush std::flush(std::cout); @@ -224,6 +226,11 @@ namespace Log fflush(stderr); } #endif + +bool isShutdown() +{ +return IsShutdown; +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/common/Log.hpp b/common/Log.hpp index fc0408088..6690c01bc 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -59,6 +59,8 @@ namespace Log #if !MOBILEAPP /// Shutdown and release the logging system. void shutdown(); +/// Was shutdown() called? +bool isShutdown(); #endif char* prefix(char* buffer, std::size_t len, const char* level); @@ -289,7 +291,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (log_.trace()) \ +if (!Log::isShutdown() && log_.trace()) \ { \ LOG_BODY_(log_, TRACE, "TRC", X, true); \ } \ @@ -299,7 +301,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (log_.trace()) \ +if (!Log::isShutdown() && log_.trace()) \ { \ LOG_BODY_(log_, TRACE, "TRC", X, false);\ } \ @@ -309,7 +311,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (log_.debug()) \ +if (!Log::isShutdown() && log_.debug()) \ { \ LOG_BODY_(log_, DEBUG, "DBG", X, true); \ } \ @@ -319,7 +321,7 @@ namespace Log do\ { \ auto &log_ = Log::logger(); \ -if (log_.information()) \ +if (!Log::isShutdown() && log_.information()) \ { \ LOG_BODY_(log_, INFORMATION, "INF", X, true); \ } \ @@ -329,7 +331,7 @@ namespace Log do\ { \ auto &log_ = Log::logger(); \ -if (log_.warning()) \ +if (!Log::isShutdown() && log_.warning()) \ { \ LOG_BODY_(log_, WARNING, "WRN", X, true); \ } \ @@ -339,7 +341,7 @@ namespace Log do \ { \ auto &log_ = Log::logger(); \ -if (log_.error()) \ +if (!Log::isShutdown() && log_.error()) \ { \ LOG_BODY_(log_, ERROR, "ERR", X, tru
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp | 12 ++-- 1 file changed, 10 insertions(+), 2 deletions(-) New commits: commit c6c673ed6fb5ff213fcd3030a38e221d28e6aa86 Author: Ashod Nakashian AuthorDate: Sun Mar 24 23:16:29 2019 -0400 Commit: Ashod Nakashian CommitDate: Sat Aug 17 03:38:43 2019 +0200 wsd: cache the logger instance to avoid costly lookups Change-Id: Idf9261d46b44afc42a960146886c180e37d8d51f Reviewed-on: https://gerrit.libreoffice.org/69641 Reviewed-by: Michael Meeks Tested-by: Michael Meeks Reviewed-on: https://gerrit.libreoffice.org/71085 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index 5a0c2655d..4441eb785 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -45,11 +45,13 @@ namespace Log struct StaticNameHelper { private: -std::atomic _inited; +Poco::Logger* _logger; std::string _name; std::string _id; +std::atomic _inited; public: StaticNameHelper() : +_logger(nullptr), _inited(true) { } @@ -67,6 +69,9 @@ namespace Log void setName(const std::string& name) { _name = name; } const std::string& getName() const { return _name; } + +void setLogger(Poco::Logger* logger) { _logger = logger; }; +Poco::Logger* getLogger() { return _logger; } }; static StaticNameHelper Source; @@ -179,6 +184,7 @@ namespace Log * */ channel->open(); auto& logger = Poco::Logger::create(Source.getName(), channel, Poco::Message::PRIO_TRACE); +Source.setLogger(&logger); logger.setLevel(logLevel.empty() ? std::string("trace") : logLevel); @@ -201,7 +207,9 @@ namespace Log Poco::Logger& logger() { -return Poco::Logger::get(Source.getInited() ? Source.getName() : std::string()); +Poco::Logger* pLogger = Source.getLogger(); +return pLogger ? *pLogger + : Poco::Logger::get(Source.getInited() ? Source.getName() : std::string()); } #if !MOBILEAPP ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp | 16 common/Log.hpp | 35 +-- 2 files changed, 17 insertions(+), 34 deletions(-) New commits: commit 685709080d27d87ccb0f9bd5c8663003ea3cfb78 Author: Michael Meeks AuthorDate: Sat Apr 27 22:15:48 2019 +0100 Commit: Michael Meeks CommitDate: Sat Apr 27 23:18:11 2019 +0200 Revert attempts at re-using ostringstream Cleaning up the thread variable with the shared string stream is something of a nightmare, for a rather marginal gain. ==9296== Invalid write of size 1 ... ==9296==by 0x738C092: str (sstream:195) ==9296==by 0x738C092: std::__cxx11::basic_ostringstream, std::allocator >::str(std::__cxx11::basic_string, std::allocator > const&) (sstream:649) ==9296==by 0x65383A: Log::beginLog[abi:cxx11](char const*) (Log.cpp:141) ==9296==by 0x551823: Admin::~Admin() (Admin.cpp:381) ==9296==by 0x7D9ECF7: __run_exit_handlers (exit.c:83) ==9296==by 0x7D9ED49: exit (exit.c:105) ==9296==by 0x7D86F50: (below main) (libc-start.c:342) ==9296== Address 0x8ba41c0 is 0 bytes inside a block of size 513 free'd ==9296==at 0x4C2FA1D: operator delete(void*) (vg_replace_malloc.c:576) ... ==9296==by 0x738784A: ~basic_stringbuf (sstream:65) ==9296==by 0x738784A: std::__cxx11::basic_ostringstream, std::allocator >::~basic_ostringstream() (sstream:591) ==9296==by 0x7D9F27E: __call_tls_dtors (cxa_thread_atexit_impl.c:155) ==9296==by 0x7D9EC0A: __run_exit_handlers (exit.c:41) ==9296==by 0x7D9ED49: exit (exit.c:105) ==9296==by 0x7D86F50: (below main) (libc-start.c:342) Good to log during shutdown / exit. This reverts commit c315d219d5967f23fb1769e78021f61b8f9da6ec. This reverts commit ce78fec310ab5ab6aecabb73cad7d782afcb885f. Change-Id: Ia4a15be336d89d8d883530943724d48e4b0ec9fe Reviewed-on: https://gerrit.libreoffice.org/71444 Reviewed-by: Michael Meeks Tested-by: Michael Meeks diff --git a/common/Log.cpp b/common/Log.cpp index 6b263263a..b892c5b4b 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -126,22 +126,6 @@ namespace Log return buffer; } -// Reuse the same buffer to minimize memory fragmentation. -static thread_local std::ostringstream Oss; - -std::ostringstream& beginLog(const char* level) -{ -// Reset the oss. -Oss.clear(); -Oss.str(std::string()); -Oss.seekp(0); - -// Output the prefix. -char buffer[1024]; -Oss << Log::prefix(buffer, sizeof(buffer) - 1, level) << std::boolalpha; -return Oss; -} - void signalLogPrefix() { char buffer[1024]; diff --git a/common/Log.hpp b/common/Log.hpp index cc4ef9d83..bdc654b39 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -54,9 +54,6 @@ namespace Log char* prefix(char* buffer, std::size_t len, const char* level); -/// Starts logging by generating the prefix and returning an oss. -std::ostringstream& beginLog(const char* level); - inline bool traceEnabled() { return logger().trace(); } inline bool debugEnabled() { return logger().debug(); } inline bool infoEnabled() { return logger().information(); } @@ -240,29 +237,31 @@ namespace Log #define LOG_FILE_NAME(f) (strrchr(f, '/')+1) #endif -#define LOG_END(LOG, FILEP) \ -do \ -{ \ -if (FILEP) \ -LOG << "| " << LOG_FILE_NAME(__FILE__) << ':' << __LINE__; \ +#define LOG_END(LOG, FILEP) \ +do \ +{ \ +if (FILEP) \ +LOG << "| " << LOG_FILE_NAME(__FILE__) << ':' << __LINE__; \ } while (false) #ifdef __ANDROID__ -#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ -std::ostringstream& oss_ = Log::beginLog(LVL); \ -oss_ << X; \ -LOG_END(oss_, FILEP); \ +#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ +char b_[1024]; \ +std::ostringstream oss_(Log::prefix
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp |3 ++- common/Log.hpp |6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) New commits: commit c2c5bd0e3e04181bf0a21a65b83f8455b7486039 Author: Michael Meeks AuthorDate: Sat Apr 27 22:00:51 2019 +0100 Commit: Michael Meeks CommitDate: Sat Apr 27 23:03:16 2019 +0200 Reset the stringstream properly. Avoids some N^2 log-line explosion; also make the method name more findable. Change-Id: I3ee8c521f1ac98a939cd4d758c720b577d3bfa57 Reviewed-on: https://gerrit.libreoffice.org/71443 Reviewed-by: Michael Meeks Tested-by: Michael Meeks diff --git a/common/Log.cpp b/common/Log.cpp index 46cfd6095..6b263263a 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -129,10 +129,11 @@ namespace Log // Reuse the same buffer to minimize memory fragmentation. static thread_local std::ostringstream Oss; -std::ostringstream& begin(const char* level) +std::ostringstream& beginLog(const char* level) { // Reset the oss. Oss.clear(); +Oss.str(std::string()); Oss.seekp(0); // Output the prefix. diff --git a/common/Log.hpp b/common/Log.hpp index f4a51d8da..cc4ef9d83 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -55,7 +55,7 @@ namespace Log char* prefix(char* buffer, std::size_t len, const char* level); /// Starts logging by generating the prefix and returning an oss. -std::ostringstream& begin(const char* level); +std::ostringstream& beginLog(const char* level); inline bool traceEnabled() { return logger().trace(); } inline bool debugEnabled() { return logger().debug(); } @@ -250,7 +250,7 @@ namespace Log #ifdef __ANDROID__ #define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ -std::ostringstream& oss_ = Log::begin(LVL); \ +std::ostringstream& oss_ = Log::beginLog(LVL); \ oss_ << X; \ LOG_END(oss_, FILEP); \ ((void)__android_log_print(ANDROID_LOG_DEBUG, "loolwsd", "%s %s", LVL, oss_.str().c_str())) @@ -259,7 +259,7 @@ namespace Log #define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ Poco::Message m_(LOG.name(), "", Poco::Message::PRIO_##PRIO); \ -std::ostringstream& oss_ = Log::begin(LVL); \ +std::ostringstream& oss_ = Log::beginLog(LVL); \ oss_ << X; \ LOG_END(oss_, FILEP); \ m_.setText(oss_.str()); \ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp | 15 +++ common/Log.hpp | 35 ++- 2 files changed, 33 insertions(+), 17 deletions(-) New commits: commit ce78fec310ab5ab6aecabb73cad7d782afcb885f Author: Ashod Nakashian AuthorDate: Sat Apr 20 11:39:20 2019 -0400 Commit: Ashod Nakashian CommitDate: Tue Apr 23 03:01:00 2019 +0200 wsd: reuse ostringstream when logging This is faster and reduces memory fragmentation. Also, cleans up the logging macros and implementation. Change-Id: I7fb00da041d1261c694c4b48b67a3c66ad0cbf8d Reviewed-on: https://gerrit.libreoffice.org/71020 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index b892c5b4b..46cfd6095 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -126,6 +126,21 @@ namespace Log return buffer; } +// Reuse the same buffer to minimize memory fragmentation. +static thread_local std::ostringstream Oss; + +std::ostringstream& begin(const char* level) +{ +// Reset the oss. +Oss.clear(); +Oss.seekp(0); + +// Output the prefix. +char buffer[1024]; +Oss << Log::prefix(buffer, sizeof(buffer) - 1, level) << std::boolalpha; +return Oss; +} + void signalLogPrefix() { char buffer[1024]; diff --git a/common/Log.hpp b/common/Log.hpp index bdc654b39..f4a51d8da 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -54,6 +54,9 @@ namespace Log char* prefix(char* buffer, std::size_t len, const char* level); +/// Starts logging by generating the prefix and returning an oss. +std::ostringstream& begin(const char* level); + inline bool traceEnabled() { return logger().trace(); } inline bool debugEnabled() { return logger().debug(); } inline bool infoEnabled() { return logger().information(); } @@ -237,31 +240,29 @@ namespace Log #define LOG_FILE_NAME(f) (strrchr(f, '/')+1) #endif -#define LOG_END(LOG, FILEP) \ -do \ -{ \ -if (FILEP) \ -LOG << "| " << LOG_FILE_NAME(__FILE__) << ':' << __LINE__; \ +#define LOG_END(LOG, FILEP) \ +do \ +{ \ +if (FILEP) \ +LOG << "| " << LOG_FILE_NAME(__FILE__) << ':' << __LINE__; \ } while (false) #ifdef __ANDROID__ -#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ -char b_[1024]; \ -std::ostringstream oss_(Log::prefix(b_, sizeof(b_) - 1, LVL), std::ostringstream::ate); \ -oss_ << std::boolalpha << X; \ -LOG_END(oss_, FILEP); \ +#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ +std::ostringstream& oss_ = Log::begin(LVL); \ +oss_ << X; \ +LOG_END(oss_, FILEP); \ ((void)__android_log_print(ANDROID_LOG_DEBUG, "loolwsd", "%s %s", LVL, oss_.str().c_str())) #else -#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ -Poco::Message m_(LOG.name(), "", Poco::Message::PRIO_##PRIO); \ -char b_[1024]; \ -std::ostringstream oss_(Log::prefix(b_, sizeof(b_) - 1, LVL), std::ostringstream::ate); \ -oss_ << std::boolalpha << X; \ -LOG_END(oss_, FILEP); \ -m_.setText(oss_.str()); \ +#define LOG_BODY_(LOG, PRIO, LVL, X, FILEP) \ +Poco::Message m_(LOG.name(), "", Poco::Message::PRIO_##PRIO); \ +std::ostringstream& oss_ = Log::begin(LVL); \ +oss_ << X; \ +LOG_END(oss_, FILEP);
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp | 34 +++--- 1 file changed, 23 insertions(+), 11 deletions(-) New commits: commit da8785ed50448d91dd69097ffc0393a5677d9a1b Author: Miklos Vajna AuthorDate: Tue Dec 4 09:05:43 2018 +0100 Commit: Miklos Vajna CommitDate: Tue Dec 4 09:06:58 2018 +0100 Log::StaticNameHelper: make members private Change-Id: I7c46dc6757b98867c4893ee019b3fd6d903020fc diff --git a/common/Log.cpp b/common/Log.cpp index 2136de15a..617e26eca 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -44,17 +44,29 @@ namespace Log /// Helper to avoid destruction ordering issues. struct StaticNameHelper { -std::atomic inited; -std::string name; -std::string id; +private: +std::atomic _inited; +std::string _name; +std::string _id; +public: StaticNameHelper() : -inited(true) +_inited(true) { } ~StaticNameHelper() { -inited = false; +_inited = false; } + +bool getInited() const { return _inited; } + +void setId(const std::string& id) { _id = id; } + +const std::string& getId() const { return _id; } + +void setName(const std::string& name) { _name = name; } + +const std::string& getName() const { return _name; } }; static StaticNameHelper Source; @@ -105,7 +117,7 @@ namespace Log #endif Poco::DateTime time; snprintf(buffer, len, "%s-%.05lu %.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.6u [ %s ] %s ", -(Source.inited ? Source.id.c_str() : ""), +(Source.getInited() ? Source.getId().c_str() : ""), osTid, time.year(), time.month(), time.day(), time.hour(), time.minute(), time.second(), @@ -127,14 +139,14 @@ namespace Log const bool logToFile, const std::map& config) { -Source.name = name; +Source.setName(name); std::ostringstream oss; -oss << Source.name; +oss << Source.getName(); #ifndef MOBILEAPP // Just one process in a mobile app, the pid is uninteresting. oss << '-' << std::setw(5) << std::setfill('0') << Poco::Process::id(); #endif -Source.id = oss.str(); +Source.setId(oss.str()); // Configure the logger. AutoPtr channel; @@ -158,7 +170,7 @@ namespace Log * after chroot can cause file creation inside the jail instead of outside * */ channel->open(); -auto& logger = Poco::Logger::create(Source.name, channel, Poco::Message::PRIO_TRACE); +auto& logger = Poco::Logger::create(Source.getName(), channel, Poco::Message::PRIO_TRACE); logger.setLevel(logLevel.empty() ? std::string("trace") : logLevel); @@ -181,7 +193,7 @@ namespace Log Poco::Logger& logger() { -return Poco::Logger::get(Source.inited ? Source.name : std::string()); +return Poco::Logger::get(Source.getInited() ? Source.getName() : std::string()); } void shutdown() ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |8 1 file changed, 4 insertions(+), 4 deletions(-) New commits: commit 83a7a6f7446069b9690fc05b77b6063107cb6aa9 Author: Tor Lillqvist AuthorDate: Thu Sep 13 11:52:08 2018 +0300 Commit: Tor Lillqvist CommitDate: Thu Sep 13 12:06:23 2018 +0300 s/StaticNames/StaticNameHelper It is a container for one name (and used just once even), not several, so no need for the plural. Change-Id: I6d8b22f071d5136fb854e6f2c5a6be8b4572b535 diff --git a/common/Log.cpp b/common/Log.cpp index 115901ecc..38e93c2cb 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -40,21 +40,21 @@ namespace Log using namespace Poco; /// Helper to avoid destruction ordering issues. -struct StaticNames +struct StaticNameHelper { std::atomic inited; std::string name; std::string id; -StaticNames() : +StaticNameHelper() : inited(true) { } -~StaticNames() +~StaticNameHelper() { inited = false; } }; -static StaticNames Source; +static StaticNameHelper Source; // We need a signal safe means of writing messages // $ man 7 signal ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp kit/Kit.cpp test/helpers.hpp wsd/TileCache.cpp wsd/TileCache.hpp
common/Log.cpp|2 +- common/Log.hpp|2 +- kit/Kit.cpp |2 +- test/helpers.hpp |2 +- wsd/TileCache.cpp |2 +- wsd/TileCache.hpp |2 +- 6 files changed, 6 insertions(+), 6 deletions(-) New commits: commit 9ed7c1065cfbeecf338b266030586048d24cb4d0 Author: Miklos Vajna AuthorDate: Mon Aug 13 09:26:09 2018 +0200 Commit: Miklos Vajna CommitDate: Mon Aug 13 09:26:15 2018 +0200 common, kit, test, wsd: these parameters are copied for each invocation ... ... but passing by const ref is enough diff --git a/common/Log.cpp b/common/Log.cpp index a3140bd48..6f398a3eb 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -131,7 +131,7 @@ namespace Log const std::string& logLevel, const bool withColor, const bool logToFile, -std::map config) +const std::map& config) { Source.name = name; std::ostringstream oss; diff --git a/common/Log.hpp b/common/Log.hpp index 1a4f69cdd..0ae6a2a7e 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -38,7 +38,7 @@ namespace Log const std::string& logLevel, const bool withColor, const bool logToFile, -std::map config); +const std::map& config); Poco::Logger& logger(); char* prefix(char* buffer, const char* level, bool sigSafe); diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 5a2148afa..07befa2b6 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -190,7 +190,7 @@ namespace } } -void linkOrCopyFile(const char *fpath, Path newPath) +void linkOrCopyFile(const char *fpath, const Path& newPath) { if (linkOrCopyVerboseLogging) LOG_INF("Linking file \"" << fpath << "\" to \"" << newPath.toString() << "\""); diff --git a/test/helpers.hpp b/test/helpers.hpp index 366ee9ff1..54c37a8ce 100644 --- a/test/helpers.hpp +++ b/test/helpers.hpp @@ -318,7 +318,7 @@ std::string getResponseString(T& ws, const std::string& prefix, const std::strin } template -std::string assertResponseString(T& ws, const std::string& prefix, const std::string testname) +std::string assertResponseString(T& ws, const std::string& prefix, const std::string& testname) { const auto res = getResponseString(ws, prefix, testname); CPPUNIT_ASSERT_EQUAL(prefix, res.substr(0, prefix.length())); diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp index 139d325d2..c7743a5cc 100644 --- a/wsd/TileCache.cpp +++ b/wsd/TileCache.cpp @@ -120,7 +120,7 @@ std::shared_ptr TileCache::findTileBeingRendered(c return tile != _tilesBeingRendered.end() ? tile->second : nullptr; } -void TileCache::forgetTileBeingRendered(std::shared_ptr tileBeingRendered, const TileDesc& tile) +void TileCache::forgetTileBeingRendered(const std::shared_ptr& tileBeingRendered, const TileDesc& tile) { assertCorrectThread(); assert(tileBeingRendered); diff --git a/wsd/TileCache.hpp b/wsd/TileCache.hpp index e4573b465..dbee88304 100644 --- a/wsd/TileCache.hpp +++ b/wsd/TileCache.hpp @@ -79,7 +79,7 @@ public: /// Store the timestamp to modtime.txt. void saveLastModified(const Poco::Timestamp& timestamp); -void forgetTileBeingRendered(std::shared_ptr tileBeingRendered, const TileDesc& tile); +void forgetTileBeingRendered(const std::shared_ptr& tileBeingRendered, const TileDesc& tile); double getTileBeingRenderedElapsedTimeMs(const std::string& tileCacheName) const; void setThreadOwner(const std::thread::id &id) { _owner = id; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |4 1 file changed, 4 deletions(-) New commits: commit eae43a262ba36bde802b5d0108757220dd38d50b Author: Tor Lillqvist Date: Thu Jul 19 12:08:26 2018 +0300 Drop unused LogPrefix variable Also gets rid of a potentially problematic strncpy() use that causes a gcc warning: specified bound 256 equals destination size [-Werror=stringop-truncation]. (Whether that would have caused a problem or not depends on how LogPrefix would have been used, and whether it ever would have been filled completely, without any terminating nul character, by that strncpy().) Change-Id: I92dba3726e3f46777d9b4c8cf88f557c02788fe0 diff --git a/common/Log.cpp b/common/Log.cpp index 4725b9024..a3140bd48 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -33,8 +33,6 @@ #include "Log.hpp" #include "Util.hpp" -static char LogPrefix[256] = { '\0' }; - namespace Log { using namespace Poco; @@ -140,8 +138,6 @@ namespace Log oss << Source.name << '-' << std::setw(5) << std::setfill('0') << Poco::Process::id(); Source.id = oss.str(); -assert (sizeof (LogPrefix) > strlen(oss.str().c_str()) + 1); -strncpy(LogPrefix, oss.str().c_str(), sizeof(LogPrefix)); // Configure the logger. AutoPtr channel; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) New commits: commit b59f5c2c65939bd7c6781deb335b186f44f14e84 Author: Ashod Nakashian Date: Thu Apr 19 08:35:23 2018 -0400 wsd: log proper ISO date in -MM-DD format Change-Id: I8851c044bad43a03a99f7471be97ea77c58f7be8 Reviewed-on: https://gerrit.libreoffice.org/53266 Reviewed-by: Jan Holesovsky Tested-by: Jan Holesovsky Reviewed-on: https://gerrit.libreoffice.org/53316 (cherry picked from commit d50850337b1cad5ce93678079085a97316f1f48e) Reviewed-on: https://gerrit.libreoffice.org/53318 diff --git a/common/Log.cpp b/common/Log.cpp index ac05d2cc6..4725b9024 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -112,9 +112,10 @@ namespace Log } Poco::DateTime time; -snprintf(buffer, 1023, "%s-%.05lu %.2u:%.2u:%.2u.%.6u [ %s ] %s ", +snprintf(buffer, 1023, "%s-%.05lu %.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.6u [ %s ] %s ", (Source.inited ? Source.id.c_str() : ""), osTid, +time.year(), time.month(), time.day(), time.hour(), time.minute(), time.second(), time.millisecond() * 1000 + time.microsecond(), threadName, level); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp test/UnitAdmin.cpp test/UnitTimeout.cpp wsd/DocumentBroker.cpp wsd/QueueHandler.hpp wsd/Storage.cpp
common/Log.cpp | 42 common/Log.hpp | 20 ++--- test/UnitAdmin.cpp | 71 ++--- test/UnitTimeout.cpp |2 - wsd/DocumentBroker.cpp | 44 +++--- wsd/QueueHandler.hpp | 10 +++--- wsd/Storage.cpp|2 - 7 files changed, 77 insertions(+), 114 deletions(-) New commits: commit c06376cc1d2e3a331e133140fc359f73783cea0e Author: Ashod Nakashian Date: Sun Jan 14 20:39:06 2018 -0500 wsd: cleanup logging and remove unused helpers Now all logging is done after checking if the level in question is enabled or not (thanks to the macros LOG_XXX), which saves unnecessary conversions and stringification when said level is disabled. Change-Id: Icde31e067f60269563896f04f8b0d65643720766 Reviewed-on: https://gerrit.libreoffice.org/47885 Reviewed-by: Michael Meeks Tested-by: Michael Meeks diff --git a/common/Log.cpp b/common/Log.cpp index 5a4f121f..ac05d2cc 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -182,53 +182,13 @@ namespace Log } oss << " Log level is [" << logger.getLevel() << "]."; -info(oss.str()); +LOG_INF(oss.str()); } Poco::Logger& logger() { return Poco::Logger::get(Source.inited ? Source.name : std::string()); } - -void trace(const std::string& msg) -{ -LOG_TRC(msg); -} - -void debug(const std::string& msg) -{ -LOG_DBG(msg); -} - -void info(const std::string& msg) -{ -LOG_INF(msg); -} - -void warn(const std::string& msg) -{ -LOG_WRN(msg); -} - -void error(const std::string& msg) -{ -LOG_ERR(msg); -} - -void syserror(const std::string& msg) -{ -LOG_SYS(msg); -} - -void fatal(const std::string& msg) -{ -LOG_FTL(msg); -} - -void sysfatal(const std::string& msg) -{ -LOG_SFL(msg); -} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/common/Log.hpp b/common/Log.hpp index 0be4983f..a3e4a9ae 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -22,6 +22,13 @@ #include #include +inline std::ostream& operator<< (std::ostream& os, const Poco::Timestamp& ts) +{ +os << Poco::DateTimeFormatter::format(Poco::DateTime(ts), + Poco::DateTimeFormat::ISO8601_FRAC_FORMAT); +return os; +} + namespace Log { void initialize(const std::string& name, @@ -33,15 +40,6 @@ namespace Log char* prefix(char* buffer, const char* level, bool sigSafe); -void trace(const std::string& msg); -void debug(const std::string& msg); -void info(const std::string& msg); -void warn(const std::string& msg); -void error(const std::string& msg); -void syserror(const std::string& msg); -void fatal(const std::string& msg); -void sysfatal(const std::string& msg); - inline bool traceEnabled() { return logger().trace(); } inline bool debugEnabled() { return logger().debug(); } inline bool infoEnabled() { return logger().information(); } @@ -177,8 +175,8 @@ namespace Log { if (lhs.enabled()) { -lhs._stream << Poco::DateTimeFormatter::format(Poco::DateTime(rhs), - Poco::DateTimeFormat::ISO8601_FRAC_FORMAT); +lhs._stream << Poco::DateTimeFormatter::format(Poco::DateTime(rhs), + Poco::DateTimeFormat::ISO8601_FRAC_FORMAT); } return lhs; diff --git a/test/UnitAdmin.cpp b/test/UnitAdmin.cpp index cbead413..acc058e4 100644 --- a/test/UnitAdmin.cpp +++ b/test/UnitAdmin.cpp @@ -79,7 +79,7 @@ private: if (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED) res = TestResult::Ok; -Log::info(std::string("testIncorrectPassword: ") + (res == TestResult::Ok ? "OK" : "FAIL")); +LOG_INF("testIncorrectPassword: " << (res == TestResult::Ok ? "OK" : "FAIL")); return res; } @@ -117,10 +117,10 @@ private: } else { -Log::info("testCorrectPassword: Invalid cookie properties"); +LOG_INF("testCorrectPassword: Invalid cookie properties"); } -Log::info(std::string("testCorrectPassword: ") + (res == TestResult::Ok ? "OK" : "FAIL")); +LOG_INF("testCorrectPassword: " << (res == TestResult::Ok ? "OK" : "FAIL")); return res; } @@ -138,7 +138,7 @@ private: _adminWs->sendFrame(testMessage.data(), testMessage.size()); if (_messageReceivedCV.wait_for(lock, std::chrono::milliseconds(_messageTimeoutMilliSeconds)) == std::cv_status::timeout) { -Log::info("testWebSocketWithoutAuth: Timed out waiting for admin console message"); +LOG_INF("testWebS
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp |6 ++ 1 file changed, 6 insertions(+) New commits: commit af13e5927d216dd53e672056d64f11766d001457 Author: Pranav Kant Date: Wed Jul 12 15:08:59 2017 +0530 Open the log channel explicitly to avoid file creation inside jail Change-Id: Ida66861e0e1c5925dbbf53d564a829eaf0fd15c7 diff --git a/common/Log.cpp b/common/Log.cpp index e4a9e995..0b19d88f 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -158,6 +158,12 @@ namespace Log else channel = static_cast(new Poco::ConsoleChannel()); +/** + * Open the channel explicitly, instead of waiting for first log message + * This is important especially for the kit process where opening the channel + * after chroot can cause file creation inside the jail instead of outside + * */ +channel->open(); auto& logger = Poco::Logger::create(Source.name, channel, Poco::Message::PRIO_TRACE); logger.setLevel(logLevel.empty() ? std::string("trace") : logLevel); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp |2 +- common/Log.hpp |2 +- 2 files changed, 2 insertions(+), 2 deletions(-) New commits: commit c22e69e9e6f4b33e7ccdd4d6057e0d92d824b651 Author: Ashod Nakashian Date: Mon Jan 30 12:39:59 2017 -0500 wsd: correct logging of thread ID in log entries Change-Id: I10aaeeea8df2757362482a405b7525542d150178 Reviewed-on: https://gerrit.libreoffice.org/33857 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index 5defd6b..f4c4589 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -84,7 +84,7 @@ namespace Log } Poco::DateTime time; -snprintf(buffer, 1023, "%s-%.04lu %.2u:%.2u:%.2u.%.6u [ %s ] %s ", +snprintf(buffer, 1023, "%s-%.05lu %.2u:%.2u:%.2u.%.6u [ %s ] %s ", (Source.inited ? Source.id.c_str() : ""), osTid, time.hour(), time.minute(), time.second(), diff --git a/common/Log.hpp b/common/Log.hpp index 1a47fc6..d8788a2 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -175,7 +175,7 @@ namespace Log } } -#define LOG_BODY_(PRIO, LVL, X) Poco::Message m_(l_.name(), "", Poco::Message::PRIO_##PRIO); char b_[1024]; std::ostringstream oss_(Log::prefix(b_, LVL, m_.getTid()), std::ostringstream::ate); oss_ << std::boolalpha << X << "| " << __FILE__ << ':' << __LINE__; m_.setText(oss_.str()); l_.log(m_); +#define LOG_BODY_(PRIO, LVL, X) Poco::Message m_(l_.name(), "", Poco::Message::PRIO_##PRIO); char b_[1024]; std::ostringstream oss_(Log::prefix(b_, LVL, m_.getOsTid()), std::ostringstream::ate); oss_ << std::boolalpha << X << "| " << __FILE__ << ':' << __LINE__; m_.setText(oss_.str()); l_.log(m_); #define LOG_TRC(X) do { auto& l_ = Log::logger(); if (l_.trace()) { LOG_BODY_(TRACE, "TRC", X); } } while (false) #define LOG_DBG(X) do { auto& l_ = Log::logger(); if (l_.debug()) { LOG_BODY_(DEBUG, "DBG", X); } } while (false) #define LOG_INF(X) do { auto& l_ = Log::logger(); if (l_.information()) { LOG_BODY_(INFORMATION, "INF", X); } } while (false) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp common/Log.hpp
common/Log.cpp | 49 - common/Log.hpp | 41 +++-- 2 files changed, 43 insertions(+), 47 deletions(-) New commits: commit ffe092f5ce4fc1fb15cbaca3ee5f1930dd74affd Author: Ashod Nakashian Date: Thu Jan 19 19:26:57 2017 -0500 wsd: log cleanup Change-Id: I569f7a81fa80686810c4d5aa65e03b02be189db7 Reviewed-on: https://gerrit.libreoffice.org/33417 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index e201dbf..5defd6b 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -8,6 +8,8 @@ */ #include +#include +#include #include #include @@ -16,9 +18,6 @@ #include #include -#include -#include - #include #include #include @@ -76,36 +75,28 @@ namespace Log } } -static void getPrefix(char *buffer, const char* level) +char* prefix(char* buffer, const char* level, const long osTid) { -char procName[32]; // we really need only 16 +char procName[32]; if (prctl(PR_GET_NAME, reinterpret_cast(procName), 0, 0, 0) != 0) { strncpy(procName, "", sizeof(procName) - 1); } -const char* appName = (Source.inited ? Source.id.c_str() : ""); -assert(strlen(appName) + 32 + 28 < 1024 - 1); - Poco::DateTime time; -snprintf(buffer, 1023, "%s-%.04lu %.2u:%.2u:%.2u.%.6u [ %s ] %s ", appName, - syscall(SYS_gettid), - time.hour(), time.minute(), time.second(), - time.millisecond() * 1000 + time.microsecond(), - procName, level); -} - -std::string prefix(const char* level) -{ -char buffer[1024]; -getPrefix(buffer, level); -return std::string(buffer); +snprintf(buffer, 1023, "%s-%.04lu %.2u:%.2u:%.2u.%.6u [ %s ] %s ", +(Source.inited ? Source.id.c_str() : ""), +osTid, +time.hour(), time.minute(), time.second(), +time.millisecond() * 1000 + time.microsecond(), +procName, level); +return buffer; } void signalLogPrefix() { char buffer[1024]; -getPrefix(buffer, "SIG"); +prefix(buffer, "SIG", syscall(SYS_gettid)); signalLog(buffer); } @@ -167,42 +158,42 @@ namespace Log void trace(const std::string& msg) { -logger().trace(prefix("TRC") + msg); +LOG_TRC(msg); } void debug(const std::string& msg) { -logger().debug(prefix("DBG") + msg); +LOG_DBG(msg); } void info(const std::string& msg) { -logger().information(prefix("INF") + msg); +LOG_INF(msg); } void warn(const std::string& msg) { -logger().warning(prefix("WRN") + msg); +LOG_WRN(msg); } void error(const std::string& msg) { -logger().error(prefix("ERR") + msg); +LOG_ERR(msg); } void syserror(const std::string& msg) { -logger().error(prefix("ERR") + msg + " (errno: " + std::string(std::strerror(errno)) + ")"); +LOG_SYS(msg); } void fatal(const std::string& msg) { -logger().fatal(prefix("FTL") + msg); +LOG_FTL(msg); } void sysfatal(const std::string& msg) { -logger().fatal(prefix("FTL") + msg + " (errno: " + std::string(std::strerror(errno)) + ")"); +LOG_SFL(msg); } } diff --git a/common/Log.hpp b/common/Log.hpp index b4d42c7..d8788a2 100644 --- a/common/Log.hpp +++ b/common/Log.hpp @@ -10,6 +10,9 @@ #ifndef INCLUDED_LOG_HPP #define INCLUDED_LOG_HPP +#include +#include + #include #include #include @@ -24,7 +27,8 @@ namespace Log const bool logToFile, std::map config); Poco::Logger& logger(); -std::string prefix(const char* level); + +char* prefix(char* buffer, const char* level, const long osTid); void trace(const std::string& msg); void debug(const std::string& msg); @@ -35,12 +39,12 @@ namespace Log void fatal(const std::string& msg); void sysfatal(const std::string& msg); -inline bool traceEnabled() { return logger().getLevel() >= Poco::Message::PRIO_TRACE; } -inline bool debugEnabled() { return logger().getLevel() >= Poco::Message::PRIO_DEBUG; } -inline bool infoEnabled() { return logger().getLevel() >= Poco::Message::PRIO_INFORMATION; } -inline bool warnEnabled() { return logger().getLevel() >= Poco::Message::PRIO_WARNING; } -inline bool errorEnabled() { return logger().getLevel() >= Poco::Message::PRIO_ERROR; } -inline bool fatalEnabled() { return logger().getLevel() >= Poco::Message::PRIO_FATAL; } +inline bool traceEnabled() { return logger().trace(); } +inline bool debugEnabled() { return logger().debug(); } +inline b
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp | 16 1 file changed, 4 insertions(+), 12 deletions(-) New commits: commit b9c900d4599a4cb5073738884c32f700ce681e21 Author: Ashod Nakashian Date: Tue Jan 17 18:30:58 2017 -0500 wsd: format the time directly in the log prefix Change-Id: I6ad5faf8fdfa16831863bf4b8fa0568e88d0d0f8 Reviewed-on: https://gerrit.libreoffice.org/33416 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index 8d020fb..e201dbf 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -78,11 +78,6 @@ namespace Log static void getPrefix(char *buffer, const char* level) { -// FIXME: If running under systemd it is redundant to output timestamps, as those will be -// attached to messages that the systemd journalling mechanism picks up anyway, won't they? - -std::string time = DateTimeFormatter::format(Poco::Timestamp(), "%H:%M:%s"); - char procName[32]; // we really need only 16 if (prctl(PR_GET_NAME, reinterpret_cast(procName), 0, 0, 0) != 0) { @@ -92,9 +87,11 @@ namespace Log const char* appName = (Source.inited ? Source.id.c_str() : ""); assert(strlen(appName) + 32 + 28 < 1024 - 1); -snprintf(buffer, 4095, "%s-%.04lu %s [ %s ] %s ", appName, +Poco::DateTime time; +snprintf(buffer, 1023, "%s-%.04lu %.2u:%.2u:%.2u.%.6u [ %s ] %s ", appName, syscall(SYS_gettid), - time.c_str(), + time.hour(), time.minute(), time.second(), + time.millisecond() * 1000 + time.microsecond(), procName, level); } @@ -159,11 +156,6 @@ namespace Log oss << " Local time: " << buf << "."; } -if (strftime(buf, sizeof(buf), "%a %F %T%z", std::gmtime(&t)) > 0) -{ -oss << " UTC time: " << buf << "."; -} - oss << " Log level is [" << logger.getLevel() << "]."; info(oss.str()); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp | 17 - 1 file changed, 4 insertions(+), 13 deletions(-) New commits: commit 4416c836d0e1456dc80e27c8fb17a95bd195f87c Author: Jan Holesovsky Date: Fri Jan 13 16:09:47 2017 +0100 Log the time in wall-clock time, instead of since the process start. Otherwise we are getting completely confused times - various processes start at various times, so for one process the epoch start can be eg. 20 minutes later than for the other. Change-Id: I6d87e98682a5fcd0348a584cf66f7ffa5813ca66 diff --git a/common/Log.cpp b/common/Log.cpp index 380b0ed..8d020fb 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -36,8 +37,6 @@ namespace Log { using namespace Poco; -static const Poco::Int64 epochStart = Poco::Timestamp().epochMicroseconds(); - /// Helper to avoid destruction ordering issues. struct StaticNames { @@ -82,15 +81,7 @@ namespace Log // FIXME: If running under systemd it is redundant to output timestamps, as those will be // attached to messages that the systemd journalling mechanism picks up anyway, won't they? -Poco::Int64 usec = Poco::Timestamp().epochMicroseconds() - epochStart; - -const Poco::Int64 one_s = 100; -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::string time = DateTimeFormatter::format(Poco::Timestamp(), "%H:%M:%s"); char procName[32]; // we really need only 16 if (prctl(PR_GET_NAME, reinterpret_cast(procName), 0, 0, 0) != 0) @@ -101,9 +92,9 @@ namespace Log const char* appName = (Source.inited ? Source.id.c_str() : ""); assert(strlen(appName) + 32 + 28 < 1024 - 1); -snprintf(buffer, 4095, "%s-%.04lu %d:%.2d:%.2d.%.6d [ %s ] %s ", appName, +snprintf(buffer, 4095, "%s-%.04lu %s [ %s ] %s ", appName, syscall(SYS_gettid), - (int)hours, (int)minutes, (int)seconds, (int)usec, + time.c_str(), procName, level); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: common/Log.cpp
common/Log.cpp | 19 --- 1 file changed, 16 insertions(+), 3 deletions(-) New commits: commit 89bd85fbba9855a607619bbda279c14da3d9cc5f Author: Ashod Nakashian Date: Mon Jan 9 12:33:01 2017 -0500 wsd: put_time is not supported by gcc4.8 Change-Id: Ib3b6a115ba669051474e327944cb4677575d15f3 Reviewed-on: https://gerrit.libreoffice.org/32917 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/common/Log.cpp b/common/Log.cpp index 3141abd..380b0ed 100644 --- a/common/Log.cpp +++ b/common/Log.cpp @@ -158,9 +158,22 @@ namespace Log const std::time_t t = std::time(nullptr); oss.str(""); oss.clear(); -oss << "Initializing " << name << ". Local time: " << std::put_time(std::localtime(&t), "%c %Z") -<< ". UTC: " << std::put_time(std::gmtime(&t), "%c %Z") -<< ". Log level is [" << logger.getLevel() << "]."; + +oss << "Initializing " << name << "."; + +// TODO: replace with std::put_time when we move to gcc 5+. +char buf[32]; +if (strftime(buf, sizeof(buf), "%a %F %T%z", std::localtime(&t)) > 0) +{ +oss << " Local time: " << buf << "."; +} + +if (strftime(buf, sizeof(buf), "%a %F %T%z", std::gmtime(&t)) > 0) +{ +oss << " UTC time: " << buf << "."; +} + +oss << " Log level is [" << logger.getLevel() << "]."; info(oss.str()); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits